Trying positioning in ConstraintLayout

I am trying to position my three image buttons in android studio. However, every time I use the design editor to position the image buttons in the correct place, it will not affect the launch of the application. Using an editor-editor rather than a text editor, you will receive the following message:

This view is not limited, it only has design time positions, so it will jump to (0,0) unless you add less constraints ...

How to add constraints to xml editor if that's all i need to do

Also, this line is added to the xml editor:   tools:layout_editor_absoluteY="80dp" tools:layout_editor_absoluteX="52dp" />

I am using ConstraintLayout instead of RelativeLayout ... My main code. Xml:

<ImageButton
    android:id="@+id/positive_Button"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:adjustViewBounds="true"
    android:background="@null"
    android:scaleType="fitCenter"
    app:srcCompat="@drawable/positive"
    android:gravity="left"
    tools:layout_editor_absoluteY="80dp"
    tools:layout_editor_absoluteX="39dp" />

<ImageButton
    android:id="@+id/neutral_Button"
    android:scaleType="fitCenter"
    android:layout_width="150dp"
    android:layout_height="150dp"
    app:srcCompat="@drawable/neutral"
    android:background="@null"
    android:adjustViewBounds="true"
    tools:layout_editor_absoluteY="80dp"
    tools:layout_editor_absoluteX="230dp" />

<ImageButton
    android:id="@+id/negative_Button"
    android:layout_width="150dp"
    android:layout_height="150dp"
    app:srcCompat="@drawable/negative"
    android:background="@null"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    tools:layout_editor_absoluteY="80dp"
    tools:layout_editor_absoluteX="412dp" />

      

+3


source to share


3 answers


In the Design Editor tab, right-click on your widget, which is ConstraintLayout, and then click Infer Constraints in the drop-down list. The IDE will automatically add the code for your.



Constraint Layout ---> Infer Constraint

      

+4


source


Attribute Tools: Used for development purposes only. Tools: Attributes are removed on creation. How would you like to position the views? Then I can suggest a solution. you can use

Android: layout_marginLeft = "80dp"



To place X, for example.

+1


source


enter image description here

in MainActivity.java

change Activity

toAppCompactActivity

0


source







All Articles