使切换按钮彼此粘在一起

时间:2016-03-08 16:02:53

标签: android xml layout toggle

如何通过移除toggle buttontoggleSun之间的空格来使toggleMon相互粘贴?

我添加

android:layout_toRightOf="@+id/toggleSun"
android:layout_toEndOf="@id/toggleSun"

toggleMon元素中,但空间仍然存在。

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

    <ToggleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New ToggleButton"
        android:checked="false"
        android:id="@+id/toggleMon" />

    <ToggleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New ToggleButton"
        android:id="@+id/toggleSun"
        android:checked="false" />
        </LinearLayout>

</LinearLayout>

任何人?

2 个答案:

答案 0 :(得分:2)

只需添加:android:layout_marginLeft =&#34; -10dp&#34;

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<ToggleButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New ToggleButton"
    android:checked="false"
    android:id="@+id/toggleMon" />

<ToggleButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New ToggleButton"
    android:layout_marginLeft="-10dp"
    android:id="@+id/toggleSun"
    android:checked="false" />
</LinearLayout>

答案 1 :(得分:1)

使它成为主视图,因为RelativeLayout将使两个ToggleButtons相互重叠。所以在较低的ToggleButton上使用属性android:layout_toRightOf =“@ id / toggleMon”。 这样,ToggleButton都可见