【问题标题】:Android: TableLayout next to LinearLayoutAndroid:LinearLayout旁边的TableLayout
【发布时间】:2011-08-28 21:22:53
【问题描述】:

在 Android 中,我尝试使用此 xml 来获取 LinearLayout 旁边的 TableLayout。但我无法让它工作。 TableLayout 总是占据屏幕的整个宽度。如何让它与 LinearLayout 共享屏幕宽度?

<LinearLayout android:layout_width="fill_parent" android:weightSum="1" android:layout_height="wrap_content" android:orientation="horizontal">
    <TableLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5">
        <TableRow>
            <TextView android:text="Name1:" />
            <TextView android:text="Value1" />
        </TableRow>     
        <TableRow>
            <TextView android:text="Name2:" />
            <TextView android:text="Value2" />
        </TableRow>             
    </TableLayout>
    <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5"></LinearLayout>
</LinearLayout>

【问题讨论】:

  • xml 工作正常,可以产生预期的结果

标签: android layout android-linearlayout tablelayout


【解决方案1】:

这表示您的线性布局的布局宽度为 0dp。使其包装内容并具有权重的表格布局:1>线性:0和表格布局设置为填充父级。

【讨论】:

    【解决方案2】:

    如上所述,不要将表格宽度设置为 0dp。我会将根元素设为相对布局,然后声明线性布局应位于表格布局的右侧。

    【讨论】:

    • 与相对布局完美搭配。我认为问题可能出在模拟器中,因为当我在真实设备上测试时,我的第一个 xml 也有效。
    猜你喜欢
    • 1970-01-01
    • 2011-12-03
    • 2011-09-09
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    相关资源
    最近更新 更多