Space between TextView and Togglebutton?

This is my code:

<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> 

When I run my application, it looks like this:

  This Button: Togglebutton 

There is a lot of space between the text view and the toggle button.

+4
source share
2 answers

If you don't need extra space, you should set both of their widths to wrap_content and wrap them in LinearLayout:

 <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> 
+3
source

Assuming you want to close the space, try android:gravity="right" in a TextView.

If this is not the case, play around setting different values ​​for android:layout_weight on TextView and ToggleButton to balance the horizontal distance.

0
source

Source: https://habr.com/ru/post/1491331/


All Articles