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);
    
                    }
                }
            });
    

      

    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-9.使用JWT生成用户Token回写客户端
    小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-8.用户模块开发之保存微信用户信息
    小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-7.授权登录获取微信用户个人信息实战
    小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-6.微信扫码登录回调本地域名映射工具Ngrock
    Vmware Briged方式使虚拟机上网
    设置VIM的配色方案
    SecureCRT辅助解决方案
    ARM标准汇编与GNU汇编
    arm:c语言和汇编混合编程
    assert()用法
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/7095420.html
Copyright © 2011-2022 走看看