如何带回RelativeLayout?

Bla*_*ard 1 android android-layout

我非常熟悉Android的RelativeLayout.但是,由于我已经更新了Android Studio(2.3),因此将ConstraintLayout设置为所有新项目的默认布局.

问题是:

  • 我无法删除ConstraintLayout.
  • 如何将它(RelativeLayout)设置为默认值,这样我就不必调整它.

我能够从这个答案中了解到调整:如何在Android Studio 2.3.3中从默认的ConstraintLayout切换到RelativeLayout

另外,请提供有关ConstraintLayout的任何有用信息,即.为什么在相对布局,关于ConstraintLayout的教程/帮助文本中使用它,以便我可以学习它.

mil*_*jon 7

要更改布局,请转到xml代码并将根布局更改为所需的布局,如果显示错误,请在此处发布错误消息.

在此输入图像描述

这部分来自我的另一个答案:https: //stackoverflow.com/a/42779569/3870382

要在创建活动时更改defalut布局,您可以修改Android Studio资源中的默认模板布局文件,转到Android Studio文件夹并转到以下文件夹路径:

\插件\机器人\ LIB \模板\活动\ COMMON\ROOT \水库\布局

编辑文件simple.xml.ftl并根据您的选择更改布局,注意一些布局需要额外的元素(例如LinearLayout需要android:orientation),在Android Studio中保存文件和创建活动,你应该得到一个你改变的xml布局的Activity .

我看起来像这样(我当时有2.2.3所以我还有RelativeLayout)

(您应该在此文件中看到您的constrainLayout,因此将其更改为relativeLayout)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
<#if hasAppBar && appBarLayoutName??>
    xmlns:app="http://schemas.android.com/apk/res-auto"
</#if>
    android:id="@+id/${simpleLayoutName}"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
<#if hasAppBar && appBarLayoutName??>
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/${appBarLayoutName}"
</#if>
    tools:context="${relativePackage}.${activityClass}">

<#if isNewProject!false>
    <TextView
<#if includeCppSupport!false>
        android:id="@+id/sample_text"
</#if>
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</#if>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)