最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android BottomSheet實現(xiàn)可拉伸控件

 更新時間:2019年11月16日 14:07:06   作者:chaoyu168  
這篇文章主要為大家詳細(xì)介紹了Android BottomSheet實現(xiàn)可拉伸控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

一、簡介

Bottom Sheet是Design Support Library23.2 版本引入的一個類似于對話框的控件。 Bottom Sheet中的內(nèi)容默認(rèn)是隱藏起來的,只顯示很小一部分,可以通過在代碼中設(shè)置其狀態(tài)或者手勢操作將其完全展開,或者完全隱藏,或者部分隱藏。

二、使用

1、添加依賴:

implementation 'com.android.support:design:28.0.0'

2、布局

<?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"
  xmlns:tools="http://schemas.android.com/tools"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
 
  <com.amap.api.maps.MapView
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
  <RelativeLayout
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/height52px"
    app:behavior_hideable="false"
    app:behavior_peekHeight="@dimen/height84px"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    tools:ignore="MissingPrefix"
    android:background="#ffffffff"
    >
 
    <include layout="@layout/bottom_sheet" />
  </RelativeLayout>
 
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="@dimen/height216px"
  >
  <TextView
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:gravity="center"
    android:text="bottom_sheet_peek" />
</RelativeLayout>

3、代碼實現(xiàn)

//底部抽屜欄展示地址
    mBehavior = BottomSheetBehavior.from(mRelativeLayout);
 
    mBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
      @Override
      public void onStateChanged(@NonNull View bottomSheet, @BottomSheetBehavior.State int newState) {
        String state = "null";
        switch (newState) {
          case 1:
            state = "STATE_DRAGGING";//過渡狀態(tài)此時用戶正在向上或者向下拖動bottom sheet
            break;
          case 2:
            state = "STATE_SETTLING"; // 視圖從脫離手指自由滑動到最終停下的這一小段時間
            break;
          case 3:
            state = "STATE_EXPANDED"; //處于完全展開的狀態(tài)
 
            break;
          case 4:
            state = "STATE_COLLAPSED"; //默認(rèn)的折疊狀態(tài)
            break;
          case 5:
            state = "STATE_HIDDEN"; //下滑動完全隱藏 bottom sheet
            break;
        }
 
      }
 
      @Override
      public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        Log.i("BottomSheetDemo", "slideOffset:" + slideOffset);
      }
    });

4、幾個屬性含義:

// behavior_hideable:定義是否能通過下滑手勢收起B(yǎng)ottom Sheet。
   app:behavior_hideable="true"
  //  behavior_peekHeight:定義可見部分的高度。
  app:behavior_peekHeight="80dp"
  app:layout_behavior="android.support.design.widget.BottomSheetBehavior"

5、BottomSheet的五種狀態(tài):

STATE_DRAGGING:手指在BottomSheet上下拖動從而使得布局跟著上下移動
STATE_SETTLING:當(dāng)手指抬起之后,會根據(jù)當(dāng)前的偏移量,決定是要將BottomSheet收起還是展開

這兩種屬于中間態(tài),類似于ViewPager的SCROLL_STATE_DRAGGING和SCROLL_STATE_SETTLING
--------------------------------------
STATE_EXPANDED:展開
STATE_COLLAPSED:收起
STATE_HIDDEN:隱藏

三、封裝的框架推薦

Flipboard/bottomsheet

soarcn/BottomSheet

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

澳门| 文昌市| 乡宁县| 通榆县| 安福县| 肥城市| 济阳县| 呼伦贝尔市| 九江市| 丰都县| 明光市| 梁平县| 绵阳市| 简阳市| 斗六市| 石楼县| 漳州市| 溆浦县| 东明县| 新丰县| 关岭| 曲阳县| 辽源市| 行唐县| 绥滨县| 宁阳县| 土默特右旗| 青铜峡市| 伊宁县| 莫力| 察哈| 象州县| 宁陵县| 武强县| 大厂| 湖南省| 孟津县| 清河县| 平武县| 永吉县| 桂阳县|