我的 Android 用户界面有问题。我的按钮没有正确对齐。即使我的按钮右对齐,但仍然无法正确对齐?
我想知道是否有任何文档可以解释如何正确布局事物以及小部件在表格行内时的行为方式?或者换句话说,层次结构如何影响事物的排列方式? 谢谢
<?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>
最佳答案
使用 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>
关于android - 安卓用户界面的规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6588827/