Android 用 SlidingUpPanelLayout 实现 Google Music 豆瓣FM 等可拖动滑动面板

767 查看

SlidingUpPanelLayout 这个库好像是基于官方的 SlidingPaneLayout 修改而来的

compile 'com.sothree.slidinguppanel:library:+'

首先是布局

<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:panelHeight="68dp"
    sothree:initialState="expanded"
    sothree:shadowHeight="4dp">

    <FrameLayout
        android:id="@+id/frameLayout_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:id="@+id/frameLayout_up"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

然后再把这两个 FrameLayout replace 上 Fragment 就可以用啦

transaction.replace(R.id.frameLayout_main, fmListFragment);
transaction.replace(R.id.frameLayout_up, playerFragment);