Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't move any elements in Android Studio for RelativeLayout

I'm trying to add some buttons/textviews or any other components to my relativelayout. I can't place them anywhere but top left. However, if I edit XML code it works fine.

Here is the screenshot of current status

I already changed my layout to relativeLayout but still no luck. (Android Studio 3.3)

My layout xml is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/activity_main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</RelativeLayout>

I would expect to move these buttons/textviews relative to each other but they just stuck at top left.

like image 387
BurakS Avatar asked Jan 25 '19 13:01

BurakS


People also ask

How do I move Textview in RelativeLayout?

there is a magnetic button on top of view editor its called (on/off auto connect ). if you change it you can move the views inside relative layout.

Is RelativeLayout deprecated?

relativelayout is deprecated now.

Which is better LinearLayout or RelativeLayout?

LinearLayout is less used as compared to RelativeLayout. RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

Which is better RelativeLayout or ConstraintLayout?

If you have the choice start with ConstraintLayout, but if you already have your app in RelativeLayout, stay with it. That's all I have been following. RelativeLayout is very limited in functionality and many complex layouts can't be made using it, especially when ratios are involved.


2 Answers

there is a magnetic button on top of view editor its called (on/off auto connect ). if you change it you can move the views inside relative layout.

like image 195
ronin shahi Avatar answered Oct 21 '22 00:10

ronin shahi


Just Enable AutoConnection to Parent In Design Mode click the magnet icon and choose "AutoConnection to Parent" enter image description here

like image 37
mohammad Avatar answered Oct 21 '22 00:10

mohammad