0

can someone show me how to make a switch and a label look this way? https://www.androidhive.info/wp-content/uploads/2017/06/android-settings-preferences.png (the top right one, Vibrate) where the label is to the left and the switch is to th right --- here's waht i have so far

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow>
        <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" >
            <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Invert Colors"></TextView>
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"/>

        </LinearLayout>
    </TableRow>

</TableLayout>


</android.support.constraint.ConstraintLayout>

but it looks like this

not what i want

David Kachlon
  • 201
  • 3
  • 14

1 Answers1

1

You can change the layout to RelativeLayout or ConstraintLayout to align this switch to the parent right.

Or use the built-in PreferenceScreen which is designed & recommended for settings activity. Ex:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
        android:key="setting_title_notifications"
        android:title="Notifications">

    <CheckBoxPreference
        android:id="@+id/setting_vibrate"
        android:key="setting_vibrate"
        android:title="Vibrate"
        android:summary="Vibrate on new notification" />
    </PreferenceCategory>
</PreferenceScreen>
nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
  • https://hastebin.com/oyejiwuyom.xml <- this XML but this result https://snag.gy/nV8kcg.jpg isn't what i'm getting.. im getting this https://snag.gy/HUysbh.jpg – David Kachlon May 24 '18 at 04:19
  • @DavidKachlon try run the app to your device or try those solution: https://stackoverflow.com/questions/34499839/android-studio-does-not-show-layout-preview – nhoxbypass May 24 '18 at 04:35