代码之家  ›  专栏  ›  技术社区  ›  Abs

与Android布局抗争

  •  1
  • Abs  · 技术社区  · 15 年前

    我在努力 create this layout [图片链接] 对于我的Android应用程序。

    我试着把几个东西嵌套在一起,但是我不断地出错,最后我得到了一些代码,它们和我想要的完全不同。我希望我能知道应该使用什么布局以及如何将它们嵌套在一起。

    这是我的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 回复  |  直到 13 年前
        1
  •  2
  •   Asahi    15 年前

    我会和你一起去的 RelativeLayout 包括另一个 相对布局 在屏幕的上部(这里和其余的大字)

        2
  •  0
  •   Franco    15 年前

    我也会选择相对布局,也许,如果你是一个新的安卓开发人员,想要在所见即所得的IDE上测试你的布局,你可以使用DroidDraw…

        3
  •  0
  •   Snailer    15 年前

    伪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>
    
        4
  •  0
  •   pritisikha    15 年前

    我想,你可以在“视图翻转器”下使用TableLayout。并对所有文本和按钮使用TableRow,在表布局中也使用属性“StretchColumns”,这将帮助您添加所需的列数。

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

    这对我有很大帮助。

        5
  •  0
  •   Wesley Wiser    13 年前

    你应该尝试使用 RelativeLayout 而不是 TableLayout . 看看这个 tutorial