我在 RecyclerView
中有一个项目布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:rowCount="2">
<ImageView
android:id="@+id/imageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_rowSpan="2" />
<TextView
android:id="@+id/textView"
android:layout_row="0"
android:layout_column="1"
android:layout_marginRight="8dp"
android:padding="8dp" />
<android.webkit.WebView
android:id="@+id/webView"
android:layout_height="200dp"
android:layout_row="1"
android:layout_column="1"
android:layout_marginRight="8dp" />
</GridLayout>
问题是,TextView
和 WebView
延伸到了我预期的区域之外。它们的右侧被切断。它们被切断的量看起来就像是第一列的宽度。
造成这种情况的原因是什么以及如何纠正?
最佳答案
将第二列中的项目设置为宽度为 0dp,并将 android:layout_gravity 设置为水平填充。这应该可以防止它们被剪裁。
关于android - GridLayout 子级被剪裁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37744672/