Android UI的规则

时间:2011-07-05 21:03:11

标签: android android-layout android-widget

我的Android UI出现问题。我的按钮没有正确对齐。即使我的按钮向右对齐,但仍然无法正确排列?

我想知道是否有任何文档可以解释如何正确布局事物以及窗口小部件在桌面内时的行为方式如何?或者换句话说,层次结构如何影响事物的对齐方式? 感谢

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    style="?screenBackground">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent">
        <TableLayout android:id="@+id/TableLayout02"
            android:layout_width="match_parent" android:layout_height="match_parent"
            style="?pageBackground">
            <TableRow>
                <ImageView android:layout_height="wrap_content"
                    android:layout_width="wrap_content" android:src="@drawable/camera_icon"
                    android:id="@+id/img" android:layout_gravity="left"></ImageView>
                <Button android:id="@+id/button1" android:text="@string/button1"
                    style="?button"></Button>

            </TableRow>

        </TableLayout>
    </LinearLayout>
</ScrollView> 

1 个答案:

答案 0 :(得分:1)

使用RelativeLayout代替LinearLayout可能会更好运。

例如,您可以将ImageViewButton对齐:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content">

    <ImageView 
        android:layout_height="60dip"
        android:layout_width="60dip" 
        android:layout_alignParentLeft="true"/>

    <Button 
        android:text="Button" 
        android:layout_alignParentRight="true" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>

</RelativeLayout>

要了解可能的情况,RelativeLayout上的入门文档为herehere