将 TableLayout 嵌套在 LinearLayout 中 - 这可能吗?

发布于 2024-11-25 12:33:28 字数 2328 浏览 1 评论 0原文

我想要生成一个如下所示的 Android 屏幕布局:

Label   Text Field
Label   Text Field
Label   Text Field

-----Button-------
-----TextField----

也就是说,我想要在顶部有一个 TableLayout,在表格布局下方有许多项目(主要是这样我可以强制这些项目位于底部)屏幕)。我尝试按照下面的代码嵌套它们,但底部的项目似乎没有出现。

有什么想法吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:stretchColumns="1"
    android:shrinkColumns="1" android:layout_height="wrap_content"  android:layout_gravity="center_vertical">
    <TableRow>
        <TextView android:text="Latitude:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        />
        <TextView android:id="@+id/latitude"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"
        />
    </TableRow>
    <TableRow>
        <TextView android:text="Longitude:"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
        <TextView android:id="@+id/longitude"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
    </TableRow>
    <TableRow>
        <TextView android:text="Altitude:"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
        <TextView android:id="@+id/altitude"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
    </TableRow>
    <TableRow>
        <TextView android:text="Accuracy:"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
        <TextView android:id="@+id/accuracy"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
    </TableRow>
</TableLayout>
<Button android:id="@+id/save"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Save"/>
<TextView android:text="Test"/>
</LinearLayout>

I want to produce an Android screen layout that looks something like the following:

Label   Text Field
Label   Text Field
Label   Text Field

-----Button-------
-----TextField----

That is, I want to have a TableLayout at the top, with a number of items underneath the table layout (mainly so I can force these items to be at the bottom of the screen). I have tried to nest them as in the code below, but the items at the bottom don't seem to appear.

Any ideas?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:stretchColumns="1"
    android:shrinkColumns="1" android:layout_height="wrap_content"  android:layout_gravity="center_vertical">
    <TableRow>
        <TextView android:text="Latitude:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        />
        <TextView android:id="@+id/latitude"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"
        />
    </TableRow>
    <TableRow>
        <TextView android:text="Longitude:"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
        <TextView android:id="@+id/longitude"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
    </TableRow>
    <TableRow>
        <TextView android:text="Altitude:"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
        <TextView android:id="@+id/altitude"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
    </TableRow>
    <TableRow>
        <TextView android:text="Accuracy:"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
        <TextView android:id="@+id/accuracy"
        android:text="Not available"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
    </TableRow>
</TableLayout>
<Button android:id="@+id/save"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Save"/>
<TextView android:text="Test"/>
</LinearLayout>

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

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

发布评论

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

评论(3

雨后咖啡店 2024-12-02 12:33:28

在您的表格布局中

android:layout_height="80dp"  
 android:layout_weight="1.0"

也为底部按钮添加这些,并且文本视图添加固定高度。如果您的表格需要更多空间
然后把它放在scrollView之间

in your table layout add these

android:layout_height="80dp"  
 android:layout_weight="1.0"

also for the bottom button and and text view add fixed height.If your table needs more space
then put it between scrollView

帅气尐潴 2024-12-02 12:33:28

将表格的权重设置为“1”,将高度设置为“0dp”。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:shrinkColumns="1"
        android:stretchColumns="1" >

        <TableRow>
...
        </TableRow>
    </TableLayout>

    <Button
        android:id="@+id/save"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Save" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Test" />

</LinearLayout>

Set the weight of the table to "1", and the height to "0dp".

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:shrinkColumns="1"
        android:stretchColumns="1" >

        <TableRow>
...
        </TableRow>
    </TableLayout>

    <Button
        android:id="@+id/save"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Save" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Test" />

</LinearLayout>
放赐 2024-12-02 12:33:28

对于文本字段,您必须使用 EditText 代替 TextView,并将 android:layout_heightandroid:layout_width 添加到应用程序中使用的每个小部件。

For textfield you have to use EditText in place of TextView and add android:layout_height and android:layout_width to each widget used in your application.

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