开发者

Nest TableLayout inside LinearLayout - is it possible?

开发者 https://www.devze.com 2023-03-21 23:01 出处:网络
I want to produce an Android screen layout that looks something like the following: LabelText Field LabelText Field

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"
        andr开发者_如何学Pythonoid: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>


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


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消