SlidingUpPanelLayout滑动面板布局简单使用

SlidingUpPanelLayout滑动面板布局简单使用

SlidingUpPanelLayout是github上的一个开源库https://github.com/umano/AndroidSlidingUpPanel,主要实现的效果是就是上滑或者点击展开面板带动画:
,效果图


第一步,添加依赖包

implementation 'com.sothree.slidinguppanel:library:3.4.0'

第二步,添加页面布局

<?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#DDDDDD"
    android:gravity="bottom"
    sothree:umanoClipPanel="true"
    sothree:umanoOverlay="true"
    sothree:umanoPanelHeight="145dp"
    sothree:umanoShadowHeight="0dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Main Content!"
        android:textSize="16sp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.8">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="105dp"
                    android:layout_marginTop="35dp"
                    android:background="#F8F8F8"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_marginTop="35dp"
                        android:layout_weight="1"
                        android:clickable="true"
                        android:descendantFocusability="beforeDescendants"
                        android:gravity="center"
                        android:orientation="vertical">

                        <TextView
                            android:id="@+id/entity_map_bottom_ratingTv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="行程得分"
                            android:textSize="18sp" />

                        <RatingBar
                            android:id="@+id/entity_map_bottom_ratingBar"
                            style="?android:attr/ratingBarStyleSmall"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="8dp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="40dp"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="vertical">

                        <TextView
                            android:id="@+id/entity_driver_bottom_driverNameTv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="张    四"
                            android:textSize="18sp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="35dp"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="vertical">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="行程花费"
                            android:textSize="18sp" />

                        <TextView
                            android:id="@+id/entity_driver_bottom_feeTv"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="8dp"
                            android:text="¥ 50.00"
                            android:textSize="18sp" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="#FFFFFF"></LinearLayout>
            </LinearLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent">

                <ImageView
                    android:id="@+id/entity_map_bottom_charImg"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_centerInParent="true"
                    android:src="@mipmap/ic_launcher" />
            </RelativeLayout>

        </RelativeLayout>

    </RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

总结

  1. SlidingUpPanelLayout需要放在最外层包裹。
  2. 网上说需要在styles中添加 <item name="android:windowActionBarOverlay">true</item>,经过测试加不加暂时没看到影响
  3. 有出现卡住的机率,暂未解决。
  4. sothree:umanoOverlay这个属性特别重要,用于控制背景是否融入覆盖遮罩,可以设置成false瞧瞧便知

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值