如題所示,先上代碼
<androidx.coordinatorlayout.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.test.TestSurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#d6d6d6">
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
app:behavior_hideable="true"
app:behavior_peekHeight="200dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<LinearLayout
android:id="@+id/ll_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="456" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
activity中設定
NestedScrollView scroll_bottom = findViewById(R.id.scroll_bottom);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(scroll_bottom);
// 默認隱藏
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
Button btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
});
功能就是點擊按鈕彈出BottomSheetBehavior,如果不使用SurfaceView那正常顯示。如果布局中用到了SurfaceView,那么點擊按鈕BottomSheetBehavior就被遮擋住了,請各位大佬指點
uj5u.com熱心網友回復:
view.bringToFront()方法可以讓控制元件顯示在上層。uj5u.com熱心網友回復:
這個方法試過了不好用
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/42396.html
標籤:Android
上一篇:微信開發者程式
