试试这个:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2,3,4,5,6,7,8,9,10">
<TableRow
android:background="@color/app_blue">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
... />
</TableRow>
</TableLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
这是我所做的更改以及原因:
将整个布局包装在垂直方向的 LinearLayout 中,以垂直堆叠 header 和 RecyclerView。
在标题 TableRow 中,我添加了 android:gravity="center" 以使每个 TextView 中的文本居中。
对于标题中的每个 TextView,请确保设置 android:layout_width="0dp" 和 android:layout_weight="1" 以在列之间均匀分配可用宽度。
您需要为标题中的所有列添加类似的 TextView 元素。