-2

I'm trying to put 2 buttons next to each other, but the following code doesn't do so. What should be done to put them next to each other?

<Button
    android:id="@+id/click"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click"

    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="@id/do"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.75"/>

<ImageButton
    android:id="@+id/do"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="@id/click"

    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="?attr/actionModeCopyDrawable" />
Man
  • 7
  • 1
  • 3
  • Welcome pls read [this](https://stackoverflow.com/help/how-to-ask) and post your whole xml file not just 2 buttons code – Ajay Pandya Sep 14 '19 at 10:46

2 Answers2

0

Under the Button tag change the app:layout_constraintLeft_toLeftOf to app:layout_constraintLeft_toLRightOf and under the ImageButton tag change the app:layout_constraintRight_toRightOf to app:layout_constraintRight_toLeftOf.

Also use start for left and end for right for supporting rtl layouts.

I recommend using LinearLayout for simple layouts like this.

Sepehr B
  • 41
  • 2
0

Use Linear Layout as parent of this two button and here you go the button will next to each other. And use of weight make it lot easier to compatible in all kind of screen.

<LinearLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal"
 android:weightSum="10"
 android:gravity="bottom|center">

 <Button
    android:id="@+id/click"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:weight="5"
    android:text="Click"/>

 <ImageButton
    android:id="@+id/do"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:weight="5"
    app:srcCompat="?attr/actionModeCopyDrawable"/>

</LinearLayout> 
Abhishek
  • 329
  • 3
  • 12
  • Good. Now how do I put this linearLayout between the bottom and the center of the screen? – Man Sep 14 '19 at 10:48
  • @Abhishek Use [match_parent](https://stackoverflow.com/a/5761970/3514144) instead of fill_parent – Ajay Pandya Sep 14 '19 at 10:48
  • @man you can't get a hint to design a xml layout here pls [read](https://developer.android.com/studio/write/layout-editor) – Ajay Pandya Sep 14 '19 at 10:50
  • @man Edited my answer have a look. Hope it work and let me know what is your main parent In the layout. – Abhishek Sep 14 '19 at 10:53