我使用TableLayout怎么做到横向滚动条
时间: 2024-03-16 11:45:00 浏览: 27
如果你使用 TableLayout 布局来实现表格,可以将 TableLayout 放到一个 HorizontalScrollView 中,这样就能实现横向滚动了。
例如,下面是一个简单的 TableLayout:
```
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Name"
android:textStyle="bold"/>
<TextView
android:text="Age"
android:textStyle="bold"/>
<TextView
android:text="Gender"
android:textStyle="bold"/>
</TableRow>
<TableRow>
<TextView
android:text="John"/>
<TextView
android:text="30"/>
<TextView
android:text="Male"/>
</TableRow>
<TableRow>
<TextView
android:text="Jane"/>
<TextView
android:text="25"/>
<TextView
android:text="Female"/>
</TableRow>
<!-- 其他行 -->
</TableLayout>
</HorizontalScrollView>
```
在上面的布局中,TableLayout 包含多个 TableRow,每个 TableRow 包含多个 TextView。HorizontalScrollView 包含 TableLayout,这样就能实现横向滚动了。需要注意的是,如果 TableLayout 的宽度大于 HorizontalScrollView 的宽度,才会出现横向滚动条。