【发布时间】:2012-01-25 16:57:13
【问题描述】:
无论屏幕分辨率如何,我都试图在表格行的中心对齐 2 个按钮,因此我试图避免使用指定的边距。 这是我的代码,它只适用于声明的边距,我正在使用重力和布局重力......对我没有任何作用。他们没有在中心对齐。 有人有想法吗?还是谢谢。
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:id="@+id/TableLayout01"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100px"
android:stretchColumns="1" >
<TableRow
android:id="@+id/TableRow01"
android:layout_gravity="center"
android:paddingLeft="50dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/image1Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="@drawable/image1"
android:gravity="center"
android:src="@drawable/image1"
android:text="@string/image1text"
android:textColor="@color/darkgrey" />
<Button
android:id="@+id/image2Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="@drawable/image2"
android:gravity="center"
android:src="@drawable/image2"
android:text="@string/image2text"
android:textColor="@color/darkgrey" />
</TableRow>
<TableRow
android:id="@+id/TableRow02"
android:paddingLeft="50dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/image3Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="@drawable/image3"
android:gravity="center"
android:src="@drawable/image3"
android:text="@string/image3text"
android:textColor="@color/darkgrey" />
<Button
android:id="@+id/image4Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="@drawable/image4"
android:gravity="center"
android:src="@drawable/image4"
android:text="@string/image4text"
android:textColor="@color/darkgrey" />
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
【问题讨论】:
标签: android center tablelayout