android - ConstraintLayout 在底部工作 TableView 中无法正常工作

标签 android android-layout android-constraintlayout android-relativelayout

问题

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 后面。

enter image description here

预期结果

handle 位于内容 View 和操作栏上方。

enter image description here

可能的解决方案

尽管我更愿意使用 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/

相关文章:

java - 如何对 Db 的列求和

Android: ScrollView 中的两个图像

Android:约束布局 - 比例调整后无法调整 ImageView 的 View 边界

android - ScrollView 中的约束布局

android - 如何正确实现 UMP SDK 以获得欧盟同意?

java.lang.NoClassDefFoundError : org. jsoup.Jsoup

android - Google Drive Sqlite db 文件从 android 应用程序上传

android - 相同的 DPI 但不同的英寸尺寸

java - 如何在自定义 Android View 中检查重力标志?

android - 如何动态调整约束布局中的textview大小以适应不同的屏幕尺寸?