Android-文本视图和切换按钮之间的空间?

Android-文本视图和切换按钮之间的空间?,android,textview,tablerow,togglebutton,Android,Textview,Tablerow,Togglebutton,这是我的代码: <TableRow android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <TextView android:id="@+id/TextView" android:layout_width="f

这是我的代码:

<TableRow
    android:layout_width="fill_parent" 
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal" > 

    <TextView
        android:id="@+id/TextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This Button:"
        android:layout_marginLeft="14dp" />

    <ToggleButton
        android:id="@+id/toggleButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="ToggleButton" />


    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent" 
        android:layout_weight="0.9" >
    </FrameLayout> 
</TableRow>     

文本视图和切换按钮之间有很大的空间。

如果您想缩小差距,请在文本视图上尝试
android:gravity=“right”


如果这不起作用,请在TextView和ToggleButton上为android:layout_weight设置不同的值,以平衡水平间距。

如果不需要额外空间,则应将两个宽度都设置为
wrap_content
,并将其以线性布局进行包装:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This Button:"
        android:layout_marginLeft="14dp" />

    <ToggleButton
        android:id="@+id/toggleButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton" />
</LinearLayout>


我认为这就是表格布局的工作原理。它试图调整以适应柱子。哦。。表格布局是问题所在?但我在左边有空间。来自Android文档():表格行的子项不需要在XML文件中指定布局宽度和布局高度属性。TableRow始终强制这些值分别为MATCH_PARENT和WRAP_CONTENT。如果将这两个值包装在线性布局中会怎么样?就像在编辑部一样,谢谢。线性布局就是答案。
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This Button:"
        android:layout_marginLeft="14dp" />

    <ToggleButton
        android:id="@+id/toggleButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButton" />
</LinearLayout>