在Android布局上苦苦挣扎

时间:2010-11-24 22:12:14

标签: java android

我在为我的Android应用程序如何create this layout [ImageShack Link] 进行挣扎。

我尝试将几个东西嵌套在一起,但我不断收到错误,我终于有一些代码没有像我想要的那样做。我希望能够了解我应该使用哪些布局以及如何将它们嵌套在一起。

这是我的XML代码:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">

    <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent" android:layout_height="fill_parent">

        <TextView android:text="94.6" android:id="@+id/id_number" android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView>

    </TableRow>

    <TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent" android:layout_height="fill_parent">

        <TextView android:text="KG" android:id="@+id/id_unit" android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView>

    </TableRow>

    <TableRow android:id="@+id/TableRow03" android:layout_width="fill_parent" android:layout_height="fill_parent">

        <Button android:text="@+id/Add" android:id="@+id/add_button" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>

        <Button android:text="@+id/View" android:id="@+id/view_button" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>

</TableRow>

</TableLayout>

5 个答案:

答案 0 :(得分:2)

我会使用RelativeLayout来查看屏幕上半部分包含另一个RelativeLayout的内容(此处为大字以及其他内容)

答案 1 :(得分:0)

我也会选择RelativeLayout,也许,如果你是Android开发人员的新手并且想要在所见即所得上测试你的布局,你可以使用droiddraw ...

答案 2 :(得分:0)

伪xml:

<Vertical LinearLayout>

    <BigWord TextView align="center" />
    <Horizontal LinearLayout>
        <TextView 1 />
        <TextView 2 />
    <Horizontal LinearLayout>

</Vertical LinearLayout>

<TableLayout>

    <TableRow>
        <TextView NothingHere />
        <TextView TextHere />
    </TableRow>
    <TableRow>
        <Button 1 />
        <Button 2 />
    </TableRow>

</TableLayout>

答案 3 :(得分:0)

您应该尝试使用RelativeLayout代替TableLayout。看看这个tutorial

答案 4 :(得分:0)

我认为,您可以在ViewFlipper下使用TableLayout ..并将TableRow用于所有文本&amp;按钮,也在表格布局中使用属性'stretchColumns',这将帮助您添加所需的列数。

你也可以从这个网站获得帮助 - http://www.knowledge-transfers.com/it/android-layout-tutorial/

这对我有很大帮助..

相关问题