gpt4 book ai didi

android - 2 行的全屏 Android 布局

转载 作者:行者123 更新时间:2023-11-29 16:24:37 25 4
gpt4 key购买 nike

我是 Android 开发的完全初学者,我正在尝试做一些我认为应该简单但似乎并不简单的事情(无论如何对我来说)。下面令人敬畏的 ascii 艺术展示了我正在努力实现的布局:

---------------------
| |
| |
| |
| |
| |
| Main View |
| |
| |
| |
| |
| |
---------------------
||btn a| |btn b||
---------------------

整个布局应该填满屏幕,底行停靠在屏幕底部(重力?),顶行占据屏幕的其余部分并且它应该是流动的(即如果设备方向改变它看起来像这样:

---------------------------
| |
| |
| Main View |
| |
| |
---------------------------
||btn a| |btn b||
---------------------------

如果我在 HTML 中工作,使用一个 TABLE 元素、两个 TR 元素(第一个的行跨度为 2)和第二行中的几个 TD 元素(第二个的对齐值设置为正确的)。 (对于阅读本文的 Web UI 人员,我会在实践中使用 DIV 元素和 CSS 进行布局)。

所以,我的问题是让第一行填充可用高度。我可以编写一个简单的算法在 java 代码中执行此操作,但更愿意使用 XML 进行布局。有什么简单的方法可以做到这一点?我的代码如下:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<WebView android:id="@+id/site"
android:layout_span="3" />
</TableRow>
<TableRow>
<Button android:id="@+id/back"
android:text="btn a" />
<View android:id="@+id/filler" />
<Button
aroid:id="@+id/forward"
android:text="btn b" />
</TableRow>
</TableLayout>

最佳答案

重量是正确的选择,试试看(已测试)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<LinearLayout android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/linearLayout2"
android:layout_weight="1">
<WebView android:layout_height="wrap_content"
android:id="@+id/site"
android:layout_width="wrap_content" />
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:layout_weight="2"
android:text="Button"
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></Button>
<Button android:layout_weight="2"
android:text="Button"
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></Button>
</LinearLayout>
</TableLayout>

关于android - 2 行的全屏 Android 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5169701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com