zoukankan      html  css  js  c++  java
  • BottomSheetBehavior 结合CoordinatorLayout实现底部栏

    1.xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <Button
                android:layout_height="40dp"
                android:layout_width="match_parent"
                android:id="@+id/btn"/>
        </LinearLayout>
    
        <android.support.v4.widget.NestedScrollView
            android:id="@+id/bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:behavior_hideable="true"
            app:behavior_peekHeight="100dp"
            app:layout_behavior="@string/bottom_sheet_behavior">
            <include
                layout="@layout/setting"/>
        </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>
    

      

    2.

       View bottomSheet = findViewById(R.id.bottom_sheet);
            final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
          behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    
            Button button= (Button) findViewById(R.id.btn);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(behavior.getState()==BottomSheetBehavior.STATE_HIDDEN){
                        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    
                    }else{
                        behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    
                    }
                }
            });
    

      

     3.区别:

      View bottomSheet = findViewById(R.id.bottom_sheet);
            final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
            behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
            Button button= (Button) findViewById(R.id.btn);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(behavior.getState()==BottomSheetBehavior.STATE_HIDDEN){
                        /**
                         * app:behavior_peekHeight="0dp"      behavior.setState(BottomSheetBehavior.STATE_EXPANDED); 只能响应一次
                         *
                         * app:behavior_peekHeight="0dp"  behavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 点击时,底部表出不来
                         *
                         * app:behavior_peekHeight="100dp"  behavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 点击按钮时,底部只弹出100dp,
                         *
                         * app:behavior_peekHeight="100dp"      behavior.setState(BottomSheetBehavior.STATE_EXPANDED); 点击按钮,底部表会完整弹出
                         */
    
                        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    
                    }else{
                        behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    
                    }
                }
            });
    

      

    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    15天学会jQuery
    android面试题-简答题(一)
    android面试题-选择填空(一)
    【Android进阶】Android面试题目整理与讲解
    Android 面试题(有详细答案)
    Android开发人员必备的10 个开发工具
    Android环境搭建
    到底如何区分什么是架构、框架、模式和平台 ?
    c#执行Dos命令
    C#打开Word
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/7095420.html
Copyright © 2011-2022 走看看