Search code examples
androidandroid-appcompatswitchcompat

Vertical alignment of an Android SwitchCompat?


In Android, is it possible to vertical align a SwitchCompat , that is, to put the text above the switch instead of on the left of the switch ?


Solution

  • are you looking for something like this ..?

    enter image description here

    try this

    <LinearLayout
        android:id="@+id/switchLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="5dp"
        android:orientation="vertical">
        <TextView
            android:id="@+id/switchTxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:text="Switch"/>
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:rotation="90"
            android:layout_margin="10dp"
            android:layout_marginLeft="3dp"
            android:id="@+id/switch1" />
    </LinearLayout>