我有最新的Android Studio(2.3 beta 3),看起来ConstraintLayout是创建项目时的默认设置。如何让Android Studio使用RelativeLayout作为新项目的默认布局元素?
好吧,我看到了上面的答案,它也适用于我。但是,我试了一下,并成功将我当前的项目转换为相对布局。做如下:
在activity_main.xml选项卡上,将其更改为文本。在它的顶部,你会发现以下内容:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
只需将xmlns之前的所有内容更改为RelativeLayout。这样做也会改变你会发现的最底线:
</android.support.constraint.ConstraintLayout>
至
</RelativeLayout>
问题解决了!快乐:P
最简单的方法是从Palette中选择Relativelayout,然后使用它.qazxsw poi
只需这样做:在组件树中右键单击ConstraintLayout并在转换视图上选择relativelayout ...
这些解决方案都不适合我...似乎直到我偶然发现这个设置,见图像。文件>设置>编辑器>布局编辑器>选中“首选XML编辑器”
RelativeLayout
将ConstraintLayout更改为RelativeLayout:这将在Android studio 3.0.1中有效
变化 - >
https://i.stack.imgur.com/9CHe7.png
成
<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.support.constraint.ConstraintLayout>
我正在为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"
编辑:
这是项目中的可选更改,我在浏览Udacity的Android开发人员课程时遇到了这个提示
如果项目中不需要约束布局,则通过删除此行然后执行gradle sync来从build.gradle中删除以下依赖项:
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
Android studio 3.0
step0:
关闭android工作室
步骤1:
转到C:\ Program Files \ Android \ Android Studio \ plugins \ android \ lib \ templates \ activities \ common \ root \ res \ layout \
第2步:
备份simple.xml.ftl
第3步:
将simple.xml.ftl更改为以下代码并保存:
<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>
对于android studio 3.1
如果您想要更改默认的android studio,请按照以下步骤操作:
第一
转到C:\ Program Files \ Android \ Android Studio \ plugins \ android \ lib \ templates \ activities \ common \ root \ res \ layout
即您安装android studio的文件目录。
然后
从另一个地方复制simple.xml只是为了备份
之后
打开simple.xml文件并替换其代码,如下所示
<?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>
但是,如果您只想更改此项目布局,只需转到activity_main.xml然后转到文本并将高级代码发布到那里
我想你想改变android studio的默认设置。无论何时创建的布局或活动,您都希望默认创建“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"
如果您再返回设计模式,则可以看到您现在具有相对布局。这也会自动更改结束标记,因此没有问题。
一个非常简短的方法是右键单击activity_main.xml设计背景并选择转换视图,然后选择Relativealayout。您在Xml文本中的代码将自动。更改。祝好运