我的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>
答案 0 :(得分:1)
使用RelativeLayout
代替LinearLayout
可能会更好运。
例如,您可以将ImageView
和Button
对齐:
<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>