Android 表格视图单元格未对齐

问题描述 投票:0回答:1
java android android-recyclerview
1个回答
0
投票

试试这个:

<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 元素。

© www.soinside.com 2019 - 2024. All rights reserved.