Switch right of TextInputLayout Android












-1















I would like to place a Switch right of a TextInputLayout, with match_parent parameters on the TextInput and a margin.



Placing the switch to the left seems to work, however it is hidden when placing it to the right.



See the two images below:



Switch to the left



Switch to the right



As you can see the switch places itself wrongly.



Here is my XML code. The main layout is a CoordinatorLayout:



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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Social Networks"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textColor="@color/colorPrimary"
android:textStyle="bold" />

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

<android.support.design.widget.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp">

<android.support.design.widget.TextInputEditText
android:id="@+id/myprofile_google"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:textColor="@color/blue_grey_800"
android:layout_height="wrap_content"
android:hint="Google +" />

</android.support.design.widget.TextInputLayout>

<Switch
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center_vertical"/>



</LinearLayout>

</LinearLayout>

</LinearLayout>









share|improve this question



























    -1















    I would like to place a Switch right of a TextInputLayout, with match_parent parameters on the TextInput and a margin.



    Placing the switch to the left seems to work, however it is hidden when placing it to the right.



    See the two images below:



    Switch to the left



    Switch to the right



    As you can see the switch places itself wrongly.



    Here is my XML code. The main layout is a CoordinatorLayout:



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

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Social Networks"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
    android:textColor="@color/colorPrimary"
    android:textStyle="bold" />

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

    <android.support.design.widget.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="40dp">

    <android.support.design.widget.TextInputEditText
    android:id="@+id/myprofile_google"
    android:inputType="textEmailAddress"
    android:layout_width="match_parent"
    android:textColor="@color/blue_grey_800"
    android:layout_height="wrap_content"
    android:hint="Google +" />

    </android.support.design.widget.TextInputLayout>

    <Switch
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_gravity="center_vertical"/>



    </LinearLayout>

    </LinearLayout>

    </LinearLayout>









    share|improve this question

























      -1












      -1








      -1








      I would like to place a Switch right of a TextInputLayout, with match_parent parameters on the TextInput and a margin.



      Placing the switch to the left seems to work, however it is hidden when placing it to the right.



      See the two images below:



      Switch to the left



      Switch to the right



      As you can see the switch places itself wrongly.



      Here is my XML code. The main layout is a CoordinatorLayout:



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

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Social Networks"
      android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
      android:textColor="@color/colorPrimary"
      android:textStyle="bold" />

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

      <android.support.design.widget.TextInputLayout
      style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginEnd="40dp">

      <android.support.design.widget.TextInputEditText
      android:id="@+id/myprofile_google"
      android:inputType="textEmailAddress"
      android:layout_width="match_parent"
      android:textColor="@color/blue_grey_800"
      android:layout_height="wrap_content"
      android:hint="Google +" />

      </android.support.design.widget.TextInputLayout>

      <Switch
      android:layout_width="wrap_content"
      android:layout_height="30dp"
      android:layout_gravity="center_vertical"/>



      </LinearLayout>

      </LinearLayout>

      </LinearLayout>









      share|improve this question














      I would like to place a Switch right of a TextInputLayout, with match_parent parameters on the TextInput and a margin.



      Placing the switch to the left seems to work, however it is hidden when placing it to the right.



      See the two images below:



      Switch to the left



      Switch to the right



      As you can see the switch places itself wrongly.



      Here is my XML code. The main layout is a CoordinatorLayout:



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

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Social Networks"
      android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
      android:textColor="@color/colorPrimary"
      android:textStyle="bold" />

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

      <android.support.design.widget.TextInputLayout
      style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginEnd="40dp">

      <android.support.design.widget.TextInputEditText
      android:id="@+id/myprofile_google"
      android:inputType="textEmailAddress"
      android:layout_width="match_parent"
      android:textColor="@color/blue_grey_800"
      android:layout_height="wrap_content"
      android:hint="Google +" />

      </android.support.design.widget.TextInputLayout>

      <Switch
      android:layout_width="wrap_content"
      android:layout_height="30dp"
      android:layout_gravity="center_vertical"/>



      </LinearLayout>

      </LinearLayout>

      </LinearLayout>






      android xml layout switch-statement






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 16:51









      Vanhaeren ThomasVanhaeren Thomas

      7519




      7519
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Change the layout_width of your TextInputLayout to 0dp, and add this attribute to it as well:



          android:layout_weight="1"


          What's happening right now is that your TextInputLayout has a width of match_parent. What this will do is fill the entire remaining space of the parent (this is somewhat unique to LinearLayout). When your Switch is on the left, it gets enough space for it and then the TextInputLayout takes up the rest. However, when the Switch is on the right, the TextInputLayout takes up all the space first!



          Using weight instead will make sure that other components get the space they need before the weighted component gets the extra space.






          share|improve this answer































            1














            You're missing two bits in your XML.
            Firstly, the orientation on your linear layout containing both your input layout and switch. Secondly, use weighting to show both items as you've specified that the text input layout should match the parent (fill the view width in this case).



            This layout produces your desired output:



            <?xml version="1.0" encoding="utf-8"?>

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

            <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Social Networks"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold" />

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

            <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_marginEnd="40dp">

            <android.support.design.widget.TextInputEditText
            android:id="@+id/myprofile_google"
            android:inputType="textEmailAddress"
            android:layout_width="match_parent"
            android:textColor="@android:color/holo_red_dark"
            android:layout_height="wrap_content"
            android:hint="Google +" />

            </android.support.design.widget.TextInputLayout>

            <Switch
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_gravity="center_vertical"/>



            </LinearLayout>

            </LinearLayout>





            share|improve this answer































              1














              I would suggest you use RelativeLayout instead of LinearLayout, or even better redo the whole layout in a ConstraintLayout.



              The RelativeLayout implementation would probably be something like this



                              <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent">

              <android.support.design.widget.TextInputLayout
              style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
              android:id="@+id/textInputLayout"
              android:layout_toStartOf="@+id/switch"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginEnd="40dp">

              <android.support.design.widget.TextInputEditText
              android:id="@+id/myprofile_google"
              android:inputType="textEmailAddress"
              android:layout_width="match_parent"
              android:textColor="@color/blue_grey_800"
              android:layout_height="wrap_content"
              android:hint="Google +" />

              </android.support.design.widget.TextInputLayout>

              <Switch
              android:id="@+id/switch"
              android:layout_width="wrap_content"
              android:layout_height="30dp"
              android:layout_alignParentEnd="true"
              android:layout_gravity="center_vertical"/>



              </LinearLayout>





              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379284%2fswitch-right-of-textinputlayout-android%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                Change the layout_width of your TextInputLayout to 0dp, and add this attribute to it as well:



                android:layout_weight="1"


                What's happening right now is that your TextInputLayout has a width of match_parent. What this will do is fill the entire remaining space of the parent (this is somewhat unique to LinearLayout). When your Switch is on the left, it gets enough space for it and then the TextInputLayout takes up the rest. However, when the Switch is on the right, the TextInputLayout takes up all the space first!



                Using weight instead will make sure that other components get the space they need before the weighted component gets the extra space.






                share|improve this answer




























                  1














                  Change the layout_width of your TextInputLayout to 0dp, and add this attribute to it as well:



                  android:layout_weight="1"


                  What's happening right now is that your TextInputLayout has a width of match_parent. What this will do is fill the entire remaining space of the parent (this is somewhat unique to LinearLayout). When your Switch is on the left, it gets enough space for it and then the TextInputLayout takes up the rest. However, when the Switch is on the right, the TextInputLayout takes up all the space first!



                  Using weight instead will make sure that other components get the space they need before the weighted component gets the extra space.






                  share|improve this answer


























                    1












                    1








                    1







                    Change the layout_width of your TextInputLayout to 0dp, and add this attribute to it as well:



                    android:layout_weight="1"


                    What's happening right now is that your TextInputLayout has a width of match_parent. What this will do is fill the entire remaining space of the parent (this is somewhat unique to LinearLayout). When your Switch is on the left, it gets enough space for it and then the TextInputLayout takes up the rest. However, when the Switch is on the right, the TextInputLayout takes up all the space first!



                    Using weight instead will make sure that other components get the space they need before the weighted component gets the extra space.






                    share|improve this answer













                    Change the layout_width of your TextInputLayout to 0dp, and add this attribute to it as well:



                    android:layout_weight="1"


                    What's happening right now is that your TextInputLayout has a width of match_parent. What this will do is fill the entire remaining space of the parent (this is somewhat unique to LinearLayout). When your Switch is on the left, it gets enough space for it and then the TextInputLayout takes up the rest. However, when the Switch is on the right, the TextInputLayout takes up all the space first!



                    Using weight instead will make sure that other components get the space they need before the weighted component gets the extra space.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 19 '18 at 16:56









                    Ben P.Ben P.

                    23.6k32049




                    23.6k32049

























                        1














                        You're missing two bits in your XML.
                        Firstly, the orientation on your linear layout containing both your input layout and switch. Secondly, use weighting to show both items as you've specified that the text input layout should match the parent (fill the view width in this case).



                        This layout produces your desired output:



                        <?xml version="1.0" encoding="utf-8"?>

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

                        <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Social Networks"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                        android:textColor="@color/colorPrimary"
                        android:textStyle="bold" />

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

                        <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:layout_marginEnd="40dp">

                        <android.support.design.widget.TextInputEditText
                        android:id="@+id/myprofile_google"
                        android:inputType="textEmailAddress"
                        android:layout_width="match_parent"
                        android:textColor="@android:color/holo_red_dark"
                        android:layout_height="wrap_content"
                        android:hint="Google +" />

                        </android.support.design.widget.TextInputLayout>

                        <Switch
                        android:layout_width="wrap_content"
                        android:layout_height="30dp"
                        android:layout_gravity="center_vertical"/>



                        </LinearLayout>

                        </LinearLayout>





                        share|improve this answer




























                          1














                          You're missing two bits in your XML.
                          Firstly, the orientation on your linear layout containing both your input layout and switch. Secondly, use weighting to show both items as you've specified that the text input layout should match the parent (fill the view width in this case).



                          This layout produces your desired output:



                          <?xml version="1.0" encoding="utf-8"?>

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

                          <TextView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="Social Networks"
                          android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                          android:textColor="@color/colorPrimary"
                          android:textStyle="bold" />

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

                          <android.support.design.widget.TextInputLayout
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:layout_marginEnd="40dp">

                          <android.support.design.widget.TextInputEditText
                          android:id="@+id/myprofile_google"
                          android:inputType="textEmailAddress"
                          android:layout_width="match_parent"
                          android:textColor="@android:color/holo_red_dark"
                          android:layout_height="wrap_content"
                          android:hint="Google +" />

                          </android.support.design.widget.TextInputLayout>

                          <Switch
                          android:layout_width="wrap_content"
                          android:layout_height="30dp"
                          android:layout_gravity="center_vertical"/>



                          </LinearLayout>

                          </LinearLayout>





                          share|improve this answer


























                            1












                            1








                            1







                            You're missing two bits in your XML.
                            Firstly, the orientation on your linear layout containing both your input layout and switch. Secondly, use weighting to show both items as you've specified that the text input layout should match the parent (fill the view width in this case).



                            This layout produces your desired output:



                            <?xml version="1.0" encoding="utf-8"?>

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

                            <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Social Networks"
                            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                            android:textColor="@color/colorPrimary"
                            android:textStyle="bold" />

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

                            <android.support.design.widget.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:layout_marginEnd="40dp">

                            <android.support.design.widget.TextInputEditText
                            android:id="@+id/myprofile_google"
                            android:inputType="textEmailAddress"
                            android:layout_width="match_parent"
                            android:textColor="@android:color/holo_red_dark"
                            android:layout_height="wrap_content"
                            android:hint="Google +" />

                            </android.support.design.widget.TextInputLayout>

                            <Switch
                            android:layout_width="wrap_content"
                            android:layout_height="30dp"
                            android:layout_gravity="center_vertical"/>



                            </LinearLayout>

                            </LinearLayout>





                            share|improve this answer













                            You're missing two bits in your XML.
                            Firstly, the orientation on your linear layout containing both your input layout and switch. Secondly, use weighting to show both items as you've specified that the text input layout should match the parent (fill the view width in this case).



                            This layout produces your desired output:



                            <?xml version="1.0" encoding="utf-8"?>

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

                            <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Social Networks"
                            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                            android:textColor="@color/colorPrimary"
                            android:textStyle="bold" />

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

                            <android.support.design.widget.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:layout_marginEnd="40dp">

                            <android.support.design.widget.TextInputEditText
                            android:id="@+id/myprofile_google"
                            android:inputType="textEmailAddress"
                            android:layout_width="match_parent"
                            android:textColor="@android:color/holo_red_dark"
                            android:layout_height="wrap_content"
                            android:hint="Google +" />

                            </android.support.design.widget.TextInputLayout>

                            <Switch
                            android:layout_width="wrap_content"
                            android:layout_height="30dp"
                            android:layout_gravity="center_vertical"/>



                            </LinearLayout>

                            </LinearLayout>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 19 '18 at 16:56









                            davy307davy307

                            80110




                            80110























                                1














                                I would suggest you use RelativeLayout instead of LinearLayout, or even better redo the whole layout in a ConstraintLayout.



                                The RelativeLayout implementation would probably be something like this



                                                <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent">

                                <android.support.design.widget.TextInputLayout
                                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                                android:id="@+id/textInputLayout"
                                android:layout_toStartOf="@+id/switch"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginEnd="40dp">

                                <android.support.design.widget.TextInputEditText
                                android:id="@+id/myprofile_google"
                                android:inputType="textEmailAddress"
                                android:layout_width="match_parent"
                                android:textColor="@color/blue_grey_800"
                                android:layout_height="wrap_content"
                                android:hint="Google +" />

                                </android.support.design.widget.TextInputLayout>

                                <Switch
                                android:id="@+id/switch"
                                android:layout_width="wrap_content"
                                android:layout_height="30dp"
                                android:layout_alignParentEnd="true"
                                android:layout_gravity="center_vertical"/>



                                </LinearLayout>





                                share|improve this answer




























                                  1














                                  I would suggest you use RelativeLayout instead of LinearLayout, or even better redo the whole layout in a ConstraintLayout.



                                  The RelativeLayout implementation would probably be something like this



                                                  <RelativeLayout
                                  android:layout_width="match_parent"
                                  android:layout_height="match_parent">

                                  <android.support.design.widget.TextInputLayout
                                  style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                                  android:id="@+id/textInputLayout"
                                  android:layout_toStartOf="@+id/switch"
                                  android:layout_width="match_parent"
                                  android:layout_height="wrap_content"
                                  android:layout_marginEnd="40dp">

                                  <android.support.design.widget.TextInputEditText
                                  android:id="@+id/myprofile_google"
                                  android:inputType="textEmailAddress"
                                  android:layout_width="match_parent"
                                  android:textColor="@color/blue_grey_800"
                                  android:layout_height="wrap_content"
                                  android:hint="Google +" />

                                  </android.support.design.widget.TextInputLayout>

                                  <Switch
                                  android:id="@+id/switch"
                                  android:layout_width="wrap_content"
                                  android:layout_height="30dp"
                                  android:layout_alignParentEnd="true"
                                  android:layout_gravity="center_vertical"/>



                                  </LinearLayout>





                                  share|improve this answer


























                                    1












                                    1








                                    1







                                    I would suggest you use RelativeLayout instead of LinearLayout, or even better redo the whole layout in a ConstraintLayout.



                                    The RelativeLayout implementation would probably be something like this



                                                    <RelativeLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent">

                                    <android.support.design.widget.TextInputLayout
                                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                                    android:id="@+id/textInputLayout"
                                    android:layout_toStartOf="@+id/switch"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_marginEnd="40dp">

                                    <android.support.design.widget.TextInputEditText
                                    android:id="@+id/myprofile_google"
                                    android:inputType="textEmailAddress"
                                    android:layout_width="match_parent"
                                    android:textColor="@color/blue_grey_800"
                                    android:layout_height="wrap_content"
                                    android:hint="Google +" />

                                    </android.support.design.widget.TextInputLayout>

                                    <Switch
                                    android:id="@+id/switch"
                                    android:layout_width="wrap_content"
                                    android:layout_height="30dp"
                                    android:layout_alignParentEnd="true"
                                    android:layout_gravity="center_vertical"/>



                                    </LinearLayout>





                                    share|improve this answer













                                    I would suggest you use RelativeLayout instead of LinearLayout, or even better redo the whole layout in a ConstraintLayout.



                                    The RelativeLayout implementation would probably be something like this



                                                    <RelativeLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent">

                                    <android.support.design.widget.TextInputLayout
                                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                                    android:id="@+id/textInputLayout"
                                    android:layout_toStartOf="@+id/switch"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_marginEnd="40dp">

                                    <android.support.design.widget.TextInputEditText
                                    android:id="@+id/myprofile_google"
                                    android:inputType="textEmailAddress"
                                    android:layout_width="match_parent"
                                    android:textColor="@color/blue_grey_800"
                                    android:layout_height="wrap_content"
                                    android:hint="Google +" />

                                    </android.support.design.widget.TextInputLayout>

                                    <Switch
                                    android:id="@+id/switch"
                                    android:layout_width="wrap_content"
                                    android:layout_height="30dp"
                                    android:layout_alignParentEnd="true"
                                    android:layout_gravity="center_vertical"/>



                                    </LinearLayout>






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 19 '18 at 17:00









                                    alessandro gaboardialessandro gaboardi

                                    1501314




                                    1501314






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379284%2fswitch-right-of-textinputlayout-android%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                                        How to change which sound is reproduced for terminal bell?

                                        Can I use Tabulator js library in my java Spring + Thymeleaf project?