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?
<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" />
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.
just do it: in component tree right click on ConstraintLayout and select relativelayout on convert view...
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.
That helped for me. Android studio -> Build -> Clean Project.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With