如何带回RelativeLayout?

时间:2017-03-27 16:22:45

标签: android android-layout

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

问题是:

  • 我无法删除ConstraintLayout。
  • 如何将其设置为(RelativeLayout)为默认值,以便我不必调整。

我能够从这个答案中了解到的调整:How to switch from the default ConstraintLayout to RelativeLayout in Android Studio 2.3.3

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

3 个答案:

答案 0 :(得分:7)

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

enter image description here

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

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

  

\插件\机器人\ lib中\模板\活动\共同\根\ RES \布局

编辑文件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>

答案 1 :(得分:3)

您可能已经尝试过此操作,但如果没有。在项目打开的情况下转到Android Studio的顶层菜单。 &#34;窗口&#34;选项卡,然后下拉到&#34;存储当前布局为默认值&#34;和&#34;恢复到默认布局&#34;。如果默认不是您喜欢的,请下载默认布局并将其设置为默认布局。

我几乎总是使用RelativeLayout或LinearLayout ..不幸的是我不熟悉ConstraintLayout。

希望这有帮助! :)

答案 2 :(得分:0)

我正在为android studio 2.3.1回答这个问题。 将RelativeLayout设置为主布局而不是约束布局的最简单方法之一是进入文本模式并编辑xml文件,如下所示

更改此行

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

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

并检查您的结束标记更改

</android.widget.RelativeLayout>

如果它以灰色显示,请继续删除此行。

xmlns:app="http://schemas.android.com/apk/res-auto"

希望它能解决问题。

相关问题