How to switch from the default ConstraintLayout to RelativeLayout in Android Studio

前端 未结 16 1015
遥遥无期
遥遥无期 2020-12-02 07:49

I have the latest android Studio (2.3 beta 3) and it seems ConstraintLayout is the default when creating a project. How can I make Android Studio use the RelativeLayout as t

相关标签:
16条回答
  • 2020-12-02 08:39

    The easiest method is to go to your .xml file in text mode, and replace the top line:

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    

    And then proceed to replace it with:

    <android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    

    If you then go back into design mode, you can see that you now have a relative layout. This also automatically changes the end tag, so no issues there.

    0 讨论(0)
  • 2020-12-02 08:41

    I think u want to change the default settings of android studio. Whenever a layout or Activity in created u want to create "RelativeLayout" by default. In that case, flow the step below

    1. click any folder u used to create layout or Activity
    2. then "New>> Edit File Templates
    3. then go to "Other" tab
    4. select "LayoutResourceFile.xml" and "LayoutResourceFile_vertical.xml"
    5. change "${ROOT_TAG}" to "RelativeLayout"
    6. click "Ok"

    you are done

    0 讨论(0)
  • 2020-12-02 08:45

    Android studio 3.0

    step0:

    Close android studio

    step1:

    Goto C:\Program Files\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout\

    step2:

    Backup simple.xml.ftl

    step3:

    Change simple.xml.ftl to code below and save :

    <RelativeLayout 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"
    tools:context="${packageName}.${activityClass}">
    
    
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="12dp"
        android:layout_marginTop="21dp"
        android:text="don't forget to click useful if this helps. this is my first post at stackoverflow!"
        android:textSize="20sp"
        />
    
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-02 08:47

    for android studio 3.1

    If you want your default android studio change, just follow bellow steps:

    first

    go to C:\Program Files\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout

    i.e. the file directory where you have installed android studio.

    then

    copy simple.xml from another place just for backup

    after that

    open simple.xml file and replace it's code as bellow

    <?xml version="1.0" encoding="utf-8"
    <RelativeLayout 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"
    tools:context="${packageName}.${activityClass}">
    
    
    
    </RelativeLayout>
    

    but if you just want to change this project layout, just go to activity_main.xml and then go to text and post upper code to there

    0 讨论(0)
提交回复
热议问题