【问题标题】:Layout of textviews and tablerows in TableLayout - AndroidTableLayout中textviews和tablerows的布局 - Android
【发布时间】:2013-01-09 13:53:54
【问题描述】:

我想要实现的是一个简单的 3 列 11 行表。现在所有数据都显示在 1 列和 33 行中。这是输出:

Rank
Percentage
Score
1
1234
13453
2
2352435
312413
3
235325
235423

//etc...

我已经搞砸了许多 TableLayouts 的在线示例,但我的所有输出对于所有示例都保持不变。我下面的只是我尝试的最后一个。有什么建议吗?

Highscoresmain.xml

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:fillViewport="true" >"

    <TableLayout
        android:id="@+id/tableLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="1" >

        <TableRow
            android:id="@+id/rowHeader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/rank"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/percentage"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/score"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

        <TableRow
            android:id="@+id/row1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/r1r"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/r1p"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/r1s"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        <TableRow
            android:id="@+id/row2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/r2r"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/r2p"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/r2s"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

       //TableRows 1 through 10 are identical.

        <Button 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="MAIN MENU"
            android:id="@+id/homeBtn" />
    </TableLayout>
</ScrollView>

【问题讨论】:

  • 你必须在相应的表格行之间放置三个文本视图

标签: java android textview tablelayout tablerow


【解决方案1】:

对表格中的所有行都这样做

        <TableRow
        android:id="@+id/rowHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/rank"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/percentage"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/score"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        </TableRow>

【讨论】:

  • 哦,哎呀!没有注意到我马上关闭了TableRow。谢谢!
猜你喜欢
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-04
相关资源
最近更新 更多