短视频app源码,Android开发底部滑出菜单
首先依赖三方库
implementation 'androidx.appcompat:appcompat:1.2.0'implementation 'com.google.android.material:material:1.3.0'
再看主页面的布局
<?xml version&#61;"1.0" encoding&#61;"utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android&#61;"http://schemas.android.com/apk/res/android"xmlns:app&#61;"http://schemas.android.com/apk/res-auto"android:id&#61;"&#64;&#43;id/cl_chouti"android:layout_width&#61;"match_parent"android:layout_height&#61;"match_parent"><FrameLayoutandroid:layout_width&#61;"match_parent"android:layout_height&#61;"match_parent"><TextViewandroid:layout_width&#61;"match_parent"android:layout_height&#61;"match_parent"android:gravity&#61;"center"android:text&#61;"测试数据" /></FrameLayout><!--behavior_hideable布局是否可以哦隐藏--><RelativeLayoutandroid:id&#61;"&#64;&#43;id/bottom_sheet"android:layout_width&#61;"match_parent"android:layout_height&#61;"wrap_content"android:layout_alignParentBottom&#61;"true"app:behavior_hideable&#61;"false"app:behavior_peekHeight&#61;"160dp"app:layout_behavior&#61;"&#64;string/bottom_sheet_behavior"><include layout&#61;"&#64;layout/layout_bottom_sheet" /></RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
include文件<?xml version&#61;"1.0" encoding&#61;"utf-8"?>
<LinearLayout xmlns:android&#61;"http://schemas.android.com/apk/res/android"android:layout_width&#61;"match_parent"android:layout_height&#61;"wrap_content"android:background&#61;"#ffffff"android:orientation&#61;"vertical"><TextViewandroid:id&#61;"&#64;&#43;id/tv_tishi"android:layout_width&#61;"wrap_content"android:layout_height&#61;"wrap_content"android:layout_gravity&#61;"center_horizontal"android:layout_marginTop&#61;"40dp"android:text&#61;"附近热点"android:textSize&#61;"10sp" /><androidx.recyclerview.widget.RecyclerViewandroid:id&#61;"&#64;&#43;id/recyclerview"android:layout_width&#61;"match_parent"android:layout_height&#61;"300dp"android:background&#61;"&#64;color/red" />
</LinearLayout>
在看下使用方法
mainactivitypackage 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;/*** &#64;author : xiayiye5* &#64;date : 2021/3/15 09:59* 类描述 :*/
public class BottomScrollerOutActivity extends BaseActivity {&#64;Overrideprotected int getLayoutView() {return R.layout.activity_scroller_out;}&#64;Overrideprotected void initId() {//底部抽屉栏展示地址RelativeLayout bottomSheet &#61; findViewById(R.id.bottom_sheet);BottomSheetBehavior<RelativeLayout> behavior &#61; BottomSheetBehavior.from(bottomSheet);//setBottomSheetCallback已过时behavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {&#64;Overridepublic void onStateChanged(&#64;NonNull View bottomSheet, &#64;BottomSheetBehavior.State int newState) {String state &#61; "null";switch (newState) {case 1:state &#61; "STATE_DRAGGING";//过渡状态此时用户正在向上或者向下拖动bottom sheetbreak;case 2:state &#61; "STATE_SETTLING"; // 视图从脱离手指自由滑动到最终停下的这一小段时间break;case 3:state &#61; "STATE_EXPANDED"; //处于完全展开的状态break;case 4:state &#61; "STATE_COLLAPSED"; //默认的折叠状态break;case 5:state &#61; "STATE_HIDDEN"; //下滑动完全隐藏 bottom sheetbreak;default:break;}}&#64;Overridepublic void onSlide(&#64;NonNull View bottomSheet, float slideOffset) {Log.d("BottomSheetDemo", "slideOffset:" &#43; slideOffset);}});}&#64;Overrideprotected void loadData() {}
}
以上就是短视频app源码&#xff0c;Android开发底部滑出菜单&#xff0c; 更多内容欢迎关注之后的文章