Android开发之高仿百度地图底部滑出菜单
生活随笔
收集整理的這篇文章主要介紹了
Android开发之高仿百度地图底部滑出菜单
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
老套路上圖:
底部菜單滑出效果如上圖:
首先依賴三方庫
implementation 'androidx.appcompat:appcompat:1.2.0'implementation 'com.google.android.material:material:1.3.0'再看主頁面的布局
<?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.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"><FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="測試數(shù)據(jù)" /></FrameLayout><!--behavior_hideable布局是否可以哦隱藏--><RelativeLayoutandroid:id="@+id/bottom_sheet"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"app:behavior_hideable="false"app:behavior_peekHeight="160dp"app:layout_behavior="@string/bottom_sheet_behavior"><include layout="@layout/layout_bottom_sheet" /></RelativeLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>include文件
<?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"><TextViewandroid:id="@+id/tv_tishi"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="40dp"android:text="附近熱點(diǎn)"android:textSize="10sp" /><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recyclerview"android:layout_width="match_parent"android:layout_height="300dp"android:background="@color/red" /> </LinearLayout>在看下使用方法
mainactivity
package cn.xiayiye5.xiayiye5library.activity;import android.util.Log; import android.view.View; import android.widget.RelativeLayout;import androidx.annotation.NonNull;import com.google.android.material.bottomsheet.BottomSheetBehavior;import cn.xiayiye5.xiayiye5library.R;/*** @author : xiayiye5* @date : 2021/3/15 09:59* 類描述 :*/ public class BottomScrollerOutActivity extends BaseActivity {@Overrideprotected int getLayoutView() {return R.layout.activity_scroller_out;}@Overrideprotected void initId() {//底部抽屜欄展示地址RelativeLayout bottomSheet = findViewById(R.id.bottom_sheet);BottomSheetBehavior<RelativeLayout> behavior = BottomSheetBehavior.from(bottomSheet);//setBottomSheetCallback已過時behavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {@Overridepublic void onStateChanged(@NonNull View bottomSheet, @BottomSheetBehavior.State int newState) {String state = "null";switch (newState) {case 1:state = "STATE_DRAGGING";//過渡狀態(tài)此時用戶正在向上或者向下拖動bottom sheetbreak;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 sheetbreak;default:break;}}@Overridepublic void onSlide(@NonNull View bottomSheet, float slideOffset) {Log.d("BottomSheetDemo", "slideOffset:" + slideOffset);}});}@Overrideprotected void loadData() {} }特別簡單吧:源碼直達(dá)
應(yīng)用到產(chǎn)品中的效果是這樣的
總結(jié)
以上是生活随笔為你收集整理的Android开发之高仿百度地图底部滑出菜单的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 卢伟冰:小米在欧洲市场潜力很大 跟三星苹
- 下一篇: Android开发之View双指缩放Vi