【问题标题】:Android: how to split a screen for a TableLayout next to a LinearLayout?Android:如何在 LinearLayout 旁边为 TableLayout 拆分屏幕?
【发布时间】:2011-12-03 09:37:48
【问题描述】:

如何分割屏幕,让屏幕左半边是Linearlayout,右半边是Tablelayout。

我尝试将 layout_weight 设为 1 并将 weightSum 设为 2 应用于 RelativeLayout 包装器。

谁能指导我?

这是我目前得到的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="2"
>
<LinearLayout android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="1">
    <TextView  
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:text="@string/hello2" />
</LinearLayout>
<TableLayout
    android:id="@+id/Row1"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:layout_alignParentRight="true"
    >
<TableRow>
<Button android:id="@+id/Modus" 
        android:text="@string/Mode1"
        android:background="@layout/modus_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        />
<Button android:id="@+id/Modus" 
        android:text="@string/Mode2"
        android:background="@layout/modus_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        />
</TableRow>
</TableLayout>
</RelativeLayout>

【问题讨论】:

  • 它必须是一个RelativeLayout作为包装器吗?此外,当我尝试复制您在 Eclipse 中的内容时,我被告知 layout_weight 属性在 RelativeLayout 中无效。尝试使用水平 LinearLayout 作为包装器?

标签: android layout android-linearlayout android-relativelayout tablelayout


【解决方案1】:

给您的 LinearLayout 一个 id 并将 android:layout_toRightOf="@+id/your_linear_layout" 参数添加到您的 TableLayout。或者您可以使用另一个 LinearLayout 而不是 RelativeLayout。如果您不需要添加更多视图,LinearLayout 可能会更好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-24
    • 2011-08-28
    • 2012-05-11
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    相关资源
    最近更新 更多