问题
ConstraintLayout 在底部工作表中使用时无法按预期工作。在这种情况下,ConstraintLayout 包含 2 个图像,包括底部工作表中内容的句柄和 1 个 View 。内容 View 应该放置在没有发生的句柄图像下方。
实现
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="350dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<ImageView
android:id="@+id/bottom_handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_bottom_sheet_handle"
android:contentDescription="@string/saved_bottomsheet_handle_content_description"
android:elevation="16dp"
android:src="@drawable/ic_save_planet_dark_48dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_elevation_height"
android:background="@color/bottom_sheet_handle_elevation"
android:contentDescription="@string/saved_bottomsheet_handle_content_description"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/bottom_handle" />
<FrameLayout
android:id="@+id/savedContentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/bottom_handle" />
</androidx.constraintlayout.widget.ConstraintLayout>
结果
内容 View 中的操作栏 float 在句柄 View 后面。
预期结果
handle 位于内容 View 和操作栏上方。
可能的解决方案
尽管我更愿意使用 ConstraintLayout 而不是 RelativeLayout,但 RelativeLayout 在这里可以使用。
<RelativeLayout
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:elevation="16dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<ImageView
android:id="@+id/bottom_handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_bottom_sheet_handle"
android:contentDescription="@string/saved_bottomsheet_handle_content_description"
android:elevation="16dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_save_planet_dark_48dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_elevation_height"
android:background="@color/bottom_sheet_handle_elevation"
android:contentDescription="@string/saved_bottomsheet_handle_content_description"
android:layout_alignBottom="@id/bottom_handle"/>
<FrameLayout
android:layout_below="@id/bottom_handle"
android:id="@+id/savedContentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" />
</RelativeLayout>
最佳答案
尝试在约束布局中改变它
<FrameLayout
....
android:layout_height="wrap_content"
android:layout_width= "wrap_content"
>
关于android - ConstraintLayout 在底部工作 TableView 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53111793/