【问题标题】:layout ideas for android安卓的布局思路
【发布时间】:2011-04-01 08:37:44
【问题描述】:

我一直在玩弄很多不同的布局结构,但似乎找不到最适合我的解决方案。

基本上我需要 3 行,每行占据设备的 33%(高度)(在横向模式下)。我认为这是完美的,但我似乎无法找到一种方法来指定 a 的高度。我可能在某处忽略了一个属性,但我在文档中找不到它。我也想过作为一种选择,但在玩了一会儿之后,我也不确定这是否是最好的解决方案。

可以完成我需要的吗?我将在我的行中指定其他布局(主要是相对布局),但我只需要核心结构为 3 行,每行高度为 33%。

编辑 - 添加代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rellay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/table_background">
    <LinearLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
            android:id="@+id/connect"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Connect To Server" />
    </LinearLayout>
    <LinearLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView 
            android:id="@+id/label"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:scrollbars="vertical"
            android:maxLines="6"
            android:textColor="#FFFFFF" />
    </LinearLayout>
    <LinearLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:stretchColumns="1">
            <TableRow>
                <RelativeLayout
                    android:id="@+id/cardssection"
                    android:layout_column="1" />
                <Button
                    android:id="@+id/submitcards"
                    android:gravity="right"
                    android:maxWidth="10px"
                    android:text="Submit Cards"
                    android:layout_below="@id/label" />
            </TableRow>
        </TableLayout>
    </LinearLayout>     
</LinearLayout>

【问题讨论】:

    标签: android gridview tablelayout


    【解决方案1】:

    看看这里How to split the screen with two equal LinearLayouts?。您只需要在解决方案中再添加一行。注意顶层 LinearLayout 中的 android:orientation="vertical"。

    【讨论】:

    • 这是正确的。将 1 的 layout_weight 添加到您的 3 个内部 LinearLayouts 会将它们隔开到屏幕上的第 3 个位置。使用 Burov 链接中发布的解决方案,并将第三个 LinearLayout 添加到内部。仅供参考,其中一行存在语法错误(缺少双引号);并且属性没有正确命名。
    • 我尝试了你的建议,但它不起作用。我已经编辑了我的 OP 以包括我的布局结构。我还尝试将 layout_weights 更改为 1、2 和 3,认为这可能是问题所在,但它仍然不起作用。除了第一个线性布局中的按钮,我没有看到任何其他内容。
    • 将 android:orientation="vertical" 添加到顶级 LinearLayout。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多