Giter Site home page Giter Site logo

bottomsheetbehaviorexample's Introduction

使用CoordinatorLayout+BottomSheetBehavior实现抖音的评论列表效果

效果图

效果说明

  1. 支持列表滑动
  2. 只有当列表滑动到顶端时, 继续下滑, 才会收起整个评论列表. 否则只是评论列表滑动.
  3. 如果设置了评论列表的标题, 可以通过拖动标题直接收起整个评论列表, 这时不再考虑评论列表是否滑动到顶部.

项目环境

android studio 3.3 canary3.3
androidx (完全可以替换成support库)
java

实现说明

都在xml布局文件中:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <Button
            android:id="@+id/startBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:text="评论列表" />
        
    </RelativeLayout>


    <LinearLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="348dp"
        android:orientation="vertical"
        app:behavior_hideable="true"
        app:behavior_peekHeight="0dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

        <TextView
            android:id="@+id/list_title_tv"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="#3300ff00"
            android:gravity="center"
            android:text="这个是标题,可以拖住滑动" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="300dp">

        </androidx.recyclerview.widget.RecyclerView>

    </LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

bottomsheetbehaviorexample's People

Contributors

shaopx avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.