Android 的布局想法

发布于 2024-09-15 16:27:23 字数 2258 浏览 3 评论 0原文

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

本质上我需要 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>

I've been toying around with a lot of different layout structures and can't seem to find the best one for my solution.

Essentially I need 3 rows that each take up 33% (height) of the device (in landscape mode). I thought would be perfect, but I can't seem to find a way to specify the height of a . It's possible I've overlooked a property somewhere, but I can't find it in the docs. I also thought of as an option but after playing around with that for a bit, I'm not sure that's the best solution either.

Can accomplish what I need? I will have other layouts specified within my rows (RelativeLayout primarily), but I just need the core structure to be 3 rows of 33% height each.

EDIT - Added Code:

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹梦 2024-09-22 16:27:23

看看这里 如何使用两个相等的 LinearLayout?。您只需在解决方案中再添加一行即可。注意顶层 LinearLayout 的 android:orientation="vertical" 。

Take a look here How to split the screen with two equal LinearLayouts?. You just need add one more row to the solution. Note android:orientation="vertical" at the top-level LinearLayout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文