有人能找出这个 TableLayout 有什么问题吗?
我有这张表,它显示了一些名称以及一些重量、成本和数量的数字。当我尝试在另一个标题(“ID 号”)下创建另一行时,这些行都变得不正常。如果我使用wrapp_content,它似乎可以解决它,但还有另一个问题,这就是我在这里的原因。具有wrap_content 的单元格中的ID 号不会填充单元格的其余部分。如果有人可以解释这个细胞出了什么问题,请告诉我!
table.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#222222"
android:shrinkColumns="*">
<TableRow android:layout_margin="1dp" android:background="#8b4513" android:gravity="center">
<TextView
android:padding="3dip"
android:text="Basic Info"
android:textColor="#000000"
android:textSize="22dp"
android:gravity="center" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#f0e68c" android:gravity="left">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Name"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Weight"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="Cost"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Qty"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Shovel"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="6"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="50"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="23"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Shoes"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="2"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="4"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="6"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Boots"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="2"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Gloves"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="1"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="10"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="6"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Better gloves"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="2"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Hat"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="1"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="23"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="11"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#8b4513" android:gravity="center">
<TextView
android:padding="3dip"
android:text="ID Numbers"
android:textColor="#000000"
android:textSize="22dp"
android:gravity="center" />
这是其余的代码。 ID 号未填满整个单元格:
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Shovel ID"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="left"
android:padding="3dip"
android:text="12736152889977"
android:width="wrap_content"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
</TableRow>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
I have this table and it displays some names along with some numbers for weight, cost, and quantity. When I tried to make another row under another heading ("ID Numbers") the rows get all out of whack. If I wrap_content it seems to fix it but then there is another problem, which is why I'm here. The ID number in the cell that has wrap_content WILL NOT fill the rest of the cell. If someone can explain what is wrong with this cell please tell me!
table.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#222222"
android:shrinkColumns="*">
<TableRow android:layout_margin="1dp" android:background="#8b4513" android:gravity="center">
<TextView
android:padding="3dip"
android:text="Basic Info"
android:textColor="#000000"
android:textSize="22dp"
android:gravity="center" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#f0e68c" android:gravity="left">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Name"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Weight"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="Cost"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Qty"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Shovel"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="6"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="50"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="23"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Shoes"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="2"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="4"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="6"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Boots"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="2"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Gloves"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="1"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="10"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="6"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Better gloves"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="2"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="5"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Hat"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="center"
android:padding="3dip"
android:text="1"
android:textColor="#000000"
android:textSize="22dp" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="23"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="right"
android:padding="3dip"
android:text="11"
android:textColor="#000000"
android:textSize="22dp" />
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#8b4513" android:gravity="center">
<TextView
android:padding="3dip"
android:text="ID Numbers"
android:textColor="#000000"
android:textSize="22dp"
android:gravity="center" />
Here is the rest of the code. The ID number does not fill the whole cell:
</TableRow>
<TableRow android:layout_margin="1dp" android:background="#708090">
<TextView
android:gravity="left"
android:padding="3dip"
android:text="Shovel ID"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
<TextView
android:gravity="left"
android:padding="3dip"
android:text="12736152889977"
android:width="wrap_content"
android:textColor="#000000"
android:textSize="22dp"
android:background="#aaaaaa" />
</TableRow>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这种方式
显示错误是因为在 ScrollView 中只能有一个子项(或视图),但一个子项可以包含许多其他子项,如下所示。
在 ScrollView 中使用一个 LinearLayout,并在 LinearLayout 中创建两个 TableLayout。
这里 LinearLayout 将只是 ScrollView 的一个子级,但 LinearLayout 将有两个子级(两个 TableLayout)。
Try this way
The Error is showing because in ScrollView you can only have one Child (or View) but that one child can contain many other, like this.
Take one LinearLayout in your ScrollView and in LinearLayout create your two TableLayout.
Here LinearLayout will be only one child of ScrollView but LinearLayout will have two childs (Two TableLayouts).