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

      

    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    php操作mysql数据库
    Java获得某目录下文件总大小
    Flex Air 主窗口和多个子窗口从属显示 拂晓风起
    actionscript AES 加密 解密 拂晓风起
    Flex 可以拖出窗口的panel 拖动panel变为窗口 拂晓风起
    Flash builder打包as actionscript代码,发布swc 拂晓风起
    网站安全登录 web应用安全登录 密码 防截获 拂晓风起
    Flex透明窗体做法 spark的Window加Skin 拂晓风起
    PHP开发环境搭建 (XAMPP+Xdebug+netbeans,配置调试) 拂晓风起
    SSH 项目过程中遇到的问题和解决方法汇总 struts2 spring hibernate 拂晓风起
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/7095420.html
Copyright © 2020-2023  润新知