Android 在TableLayout中右对齐
我仍然没有找到一个解决方案如何在XML中做到这一点 我希望文本视图向左对齐,图像视图向右对齐,代码如下:Android 在TableLayout中右对齐,android,android-layout,alignment,tablelayout,Android,Android Layout,Alignment,Tablelayout,我仍然没有找到一个解决方案如何在XML中做到这一点 我希望文本视图向左对齐,图像视图向右对齐,代码如下: <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tr1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_height="wrap_content"
android:text="Vibration"
android:layout_width="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:src="@drawable/ic_launcher" />
</TableRow>
</TableLayout>
有什么办法吗?尝试将您的
表格行更改为以下内容:
<TableRow
android:id="@+id/tr1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Vibration"
android:gravity="left" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:gravity="right"
android:src="@drawable/ic_launcher" />
</TableRow>
不应该是:
android:layout\u alignParentLeft=“true”///用于文本框
android:layout\u alignParentRight=“true”///用于imageview。试试这个我用
android:gravity="left"
android:paddingLeft="50dp"
希望能有帮助 我修改了你的布局,这段代码适合我,希望这也适合你
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tr1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_height="fill_parent"
android:text="Vibration"
android:paddingTop="10dp"
android:paddingLeft="5dp"
android:layout_width="0dp"
android:layout_weight="70" />
<ImageView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:contentDescription="contentDescription"
android:layout_weight="30"
android:src="@drawable/ic_launcher" />
</TableRow>
</TableLayout>
为TextView和ImageView设置一个彩色背景,确保它们横跨整个表格宽度。我找到了一个解决方案,表格布局中必须有一个参数“stretchcolumns”