Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在TableLayout中右对齐_Android_Android Layout_Alignment_Tablelayout - Fatal编程技术网

Android 在TableLayout中右对齐

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_

我仍然没有找到一个解决方案如何在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_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”