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

Android 仿高德地圖可拉伸的BottomSheet的示例代碼

 更新時(shí)間:2018年07月12日 14:48:52   作者:Abby代黎明  
這篇文章主要介紹了Android 仿高德地圖可拉伸的BottomSheet的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

前言

最近項(xiàng)目中需要用到高德地圖搜索結(jié)果后的結(jié)果展示的可拉伸控件。

gaode.gif

而我看到這個(gè)效果圖,覺(jué)得這個(gè)就是一個(gè)slidingpanel,但是翻閱了一些發(fā)現(xiàn)用google自帶的bottomsheet實(shí)現(xiàn)更方便

什么是BottomSheet?

Bottom Sheet是Design Support Library23.2 版本引入的一個(gè)類似于對(duì)話框的控件,可以暫且叫做底部彈出框吧。 Bottom Sheet中的內(nèi)容默認(rèn)是隱藏起來(lái)的,只顯示很小一部分,可以通過(guò)在代碼中設(shè)置其狀態(tài)或者手勢(shì)操作將其完全展開(kāi),或者完全隱藏,或者部分隱藏。對(duì)于Bottom Sheet的描述可以在官網(wǎng)查詢:https://material.io/design/#

怎么使用?

添加依賴

implemention 'com.android.support:design:25.3.1'

布局文件

<?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:id="@+id/cl_chouti"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <FrameLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <com.amap.api.maps.MapView
   android:id="@+id/map_view"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />

  <RelativeLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center">

   <ImageView
    android:id="@+id/mark"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/poi_marker_pressed" />
   <!--為了更好與定位之后的紅點(diǎn)適配此imagview只是適配用沒(méi)有意義-->
   <ImageView
    android:layout_width="30dp"
    android:layout_height="40dp"
    android:layout_below="@+id/mark" />
  </RelativeLayout>
 </FrameLayout>

 <RelativeLayout
  android:id="@+id/bottom_sheet"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  app:behavior_hideable="true"
  app:behavior_peekHeight="160dp"
  app:layout_behavior="@string/bottom_sheet_behavior">

  <include layout="@layout/layout_bottom_sheet" />
 </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

 layout_bottom_sheet.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="#ffffff"
 android:orientation="vertical">
 <TextView
  android:id="@+id/tv_tishi"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="40dp"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="附近熱點(diǎn)"
  android:textSize="10sp"/>
 <android.support.v7.widget.RecyclerView
  android:id="@+id/recyclerview"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>
</LinearLayout>

activity中的使用

 //底部抽屜欄展示地址
  bottomSheet = findViewById(R.id.bottom_sheet);
  behavior = BottomSheetBehavior.from(bottomSheet);

  behavior.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";//過(guò)渡狀態(tài)此時(shí)用戶正在向上或者向下拖動(dòng)bottom sheet
      break;
     case 2:
      state = "STATE_SETTLING"; // 視圖從脫離手指自由滑動(dòng)到最終停下的這一小段時(shí)間
      break;
     case 3:
      state = "STATE_EXPANDED"; //處于完全展開(kāi)的狀態(tài)

      break;
     case 4:
      state = "STATE_COLLAPSED"; //默認(rèn)的折疊狀態(tài)
      break;
     case 5:
      state = "STATE_HIDDEN"; //下滑動(dòng)完全隱藏 bottom sheet
      break;
    }

   }

   @Override
   public void onSlide(@NonNull View bottomSheet, float slideOffset) {
//    Log.d("BottomSheetDemo", "slideOffset:" + slideOffset);
   }
  });

注意分析

CoordinatorLayout 是Meterial Design中的一個(gè)新控件,通過(guò)behavior用來(lái)協(xié)調(diào)其他組件, 實(shí)現(xiàn)聯(lián)動(dòng),因此父布局必須是CoordinatorLayout 。

注意到布局中,RelativeLayout中的app:layout_behavior=”@string/bottom_sheet_behavior”屬性,點(diǎn)進(jìn)去可以看到,這個(gè)屬性實(shí)際上是設(shè)置系統(tǒng)默認(rèn)實(shí)現(xiàn)的BottomSheet的behavior。原則上來(lái)說(shuō),只要是可以滾動(dòng)的View,在加上了這個(gè)屬性后,都可以作為BottomSheet來(lái)使用,建議使用NestedScrollView或者RecyclerView。

【貢獻(xiàn)源碼地址】

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

相關(guān)文章

  • Android開(kāi)發(fā)之禁止下拉通知欄的方法

    Android開(kāi)發(fā)之禁止下拉通知欄的方法

    這篇文章主要介紹了Android開(kāi)發(fā)之禁止下拉通知欄的方法,實(shí)例分析了Android權(quán)限控制與Activity相應(yīng)設(shè)置技巧,需要的朋友可以參考下
    2016-01-01
  • Android OnCreate()中獲取控件高度與寬度兩種方法詳解

    Android OnCreate()中獲取控件高度與寬度兩種方法詳解

    這篇文章主要介紹了Android OnCreate()中獲取控件高度與寬度兩種方法詳解的相關(guān)資料,這里提供了兩種方法,大家可以都看下,需要的朋友可以參考下
    2016-12-12
  • 在Android源碼中編譯出指定jar包的操作

    在Android源碼中編譯出指定jar包的操作

    這篇文章主要介紹了在Android源碼中編譯出指定jar包的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • Kotlin協(xié)程launch啟動(dòng)流程原理詳解

    Kotlin協(xié)程launch啟動(dòng)流程原理詳解

    這篇文章主要為大家介紹了Kotlin協(xié)程launch啟動(dòng)流程原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android微信支付獲取二次簽名Sign的方法

    Android微信支付獲取二次簽名Sign的方法

    這篇文章主要介紹了Android微信支付獲取二次簽名Sign的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android 多種dialog的實(shí)現(xiàn)方法(推薦)

    Android 多種dialog的實(shí)現(xiàn)方法(推薦)

    下面小編就為大家分享一篇Android 多種dialog的實(shí)現(xiàn)方法(推薦),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Android用SharedPreferences實(shí)現(xiàn)登錄注冊(cè)注銷功能

    Android用SharedPreferences實(shí)現(xiàn)登錄注冊(cè)注銷功能

    這篇文章主要為大家詳細(xì)介紹了Android用SharedPreferences實(shí)現(xiàn)登錄注冊(cè)注銷功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Flutter組件隱藏的多種方式總結(jié)

    Flutter組件隱藏的多種方式總結(jié)

    在 Flutter 開(kāi)發(fā)中,我們經(jīng)常會(huì)遇到需要?jiǎng)討B(tài)隱藏或顯示組件的需求,Flutter 提供了多種方式來(lái)實(shí)現(xiàn)這一功能,每種方式都有其獨(dú)特的適用場(chǎng)景,本文將深入探討這些方法的原理、用法以及優(yōu)缺點(diǎn),幫助您選擇最適合的方案,需要的朋友可以參考下
    2024-10-10
  • Android微信簽名知識(shí)的總結(jié)

    Android微信簽名知識(shí)的總結(jié)

    這篇文章給大家詳細(xì)總結(jié)了Android微信簽名用到的知識(shí),文中通過(guò)具體的實(shí)現(xiàn)過(guò)程給大家進(jìn)行演示,相信對(duì)大家的理解很有幫助,下面來(lái)一起看看吧。
    2016-09-09
  • Android使用phonegap從相冊(cè)里面獲取照片(代碼分享)

    Android使用phonegap從相冊(cè)里面獲取照片(代碼分享)

    本文主要介紹了使用phonegap從相冊(cè)里面獲取照片的實(shí)現(xiàn)方法代碼。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-03-03

最新評(píng)論

公安县| 田东县| 东光县| 黄冈市| 乌兰县| 长垣县| 万山特区| 绥化市| 信丰县| 湘潭县| 三原县| 清原| 新平| 乌拉特前旗| 芮城县| 江门市| 青田县| 龙泉市| 西和县| 时尚| 河北区| 太谷县| 澄江县| 仁布县| 芦山县| 瑞安市| 屯门区| 都昌县| 区。| 胶南市| 长兴县| 桦甸市| 吴堡县| 江山市| 日土县| 金山区| 景东| 深圳市| 定陶县| 罗江县| 三门县|