Jens
Jens

Reputation: 168

Trying to position view inside ConstraintLayout

I try positioning my three imagebuttons in Android-studio. However, every time I use design-editor to position the imagebuttons on the correct location, it won't take affect when I run the app. Using the design-editor and not the text editor, gives this message:

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

How do I add constraints in the xml-editor if that is all I have 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.activity xml code:

<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" />

Upvotes: 3

Views: 2809

Answers (3)

user8706432
user8706432

Reputation: 1

enter image description here

in MainActivity.java change the Activity into AppCompactActivity

Upvotes: 0

Salman
Salman

Reputation: 2471

In Editor's design tab, right click on your Widget that is ConstraintLayout and then click Infer Constraints in the drop down list. The IDE will automatically add code for your.

Constraint Layout ---> Infer Constraint

Upvotes: 4

jobbert
jobbert

Reputation: 3497

The attribute tools: is only used for development purposes. tools: attributes are stripped when building. How would you like to position the views? Then I can propose a solution. You could use

android:layout_marginLeft="80dp"

To position the X for example.

Upvotes: 1

Related Questions