Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant move a simple button around a constraint layout

I have a constraint layout defined, and inside it a button. The problem is I cant seem to move the button around as it is fixed on the top left of the screen.

Any help?

the button edges cant be dragged, it just sits there idle.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />
like image 249
Ryan Thompson Avatar asked Oct 07 '18 03:10

Ryan Thompson


People also ask

How do I change constraint layout?

Open the layout file (activity_main. xml) in Android Studio and click the Design tab at the bottom of the editor window. In the Component Tree window, right-click LinearLayout and then choose Convert layout to ConstraintLayout from the context menu.

How do I change constraint layout to relative?

just do it: in component tree right click on ConstraintLayout and select relativelayout on convert view...

Can we use RelativeLayout inside ConstraintLayout?

Most of what can be achieved in LinearLayout and RelativeLayout can be done in ConstraintLayout. However, learning the basics of LinearLayout and RelativeLayout is important before trying to understand how to use it with ConstraintLayout.


2 Answers

That helped for me. Android studio -> Build -> Clean Project.

like image 175
Stanislav Avatar answered Sep 18 '22 23:09

Stanislav


Please use constraints, in design tab, or Text tab, to position the widget, in addition to adding margin. XML code: app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent"

You could add margin in Design tab (properties pane on right-top) and then see the added XML in Text tab to view the change in XML.

By default, in Constraint layout, any widget falls to the right-top if it is not constrained.

like image 21
kush Avatar answered Sep 21 '22 23:09

kush