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