0

I am trying to create a layout (Android Studio) in which I need to vertically align various controls like Switch in below screenshot.

enter image description here

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:textAlignment="center"
        android:text="Entrée Chaude" />

    <Switch
        android:id="@+id/switchRespectMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="50px"
        android:switchMinWidth="50dp"
        android:textSize="25sp"
        android:text="RespectMenu : "
        android:checked="false"/>

    <EditText
        android:id="@+id/remarqueRespectMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="56dp"
        android:ems="10"
        android:hint="Remarque RespectMenu"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.184"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Switch
        android:id="@+id/switchGrammage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="50px"
        android:switchMinWidth="50dp"
        android:textSize="25sp"
        android:text="Grammage  : "
         />
AliSh
  • 10,085
  • 5
  • 44
  • 76
  • Make sure you use the tags relevant to the question. [tag:uiswitch] is a tag to do with the iOS switch. Also you haven't specified which layout you want to use? – Henry Twist Apr 28 '21 at 16:42
  • @HenryTwist i used Android Layout but the alignment vertical the switch not display good in above my scipt xml and screenshot of the picture thanks in advance – Kamil Kurtin Apr 28 '21 at 22:14
  • Android Layout? I'm asking about which `ViewGroup` the views are laid out in. What is the `ViewGroup` above the ones in your question? `ConstraintLayout`? `LinearLayout`? `RelativeLayout`?... – Henry Twist Apr 28 '21 at 22:18
  • What do you want aligned with what exactly? – Henry Twist Apr 28 '21 at 22:24
  • in screenshots the switches not aligned vertical you see the screenshot:https://i.stack.imgur.com/922VR.png – Kamil Kurtin Apr 28 '21 at 22:29
  • Do you mean the switches with each other? If so then that's horizontal alignment, not vertical. – Henry Twist Apr 28 '21 at 22:32
  • you see the screenshot the first switch and the second switch and third switch not aligned vertical in the same position it's decaled one the right and second not in the same position of alignement so that's vertical position – Kamil Kurtin Apr 28 '21 at 22:35
  • Alright, well we will have to agree to disagree. Good luck! – Henry Twist Apr 28 '21 at 22:46

1 Answers1

0

If you nest all the horizontal LinearLayouts that you want inside a vertical LinearLayout it should work


<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            <Switch
                android:id="@+id/switch2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Switch" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            
            <Switch
                android:id="@+id/switch1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Switch" />
        </LinearLayout>
</LinearLayout>

BittorH
  • 58
  • 6