如何更改Android Studio的默认行为

时间:2018-03-04 18:09:18

标签: android android-relativelayout android-constraintlayout

我们可以将Android Studio的默认构建行为从约束更改为相对布局吗?

问题:有时需要更多时间来清理/重建我的项目。我从不使用Constraint Layout,因此我想将Android Studio的构建行为从Constraint Layout设置为Relative Layout

我希望每次打开AS,都应该打开Relative。有可能实现吗?

3 个答案:

答案 0 :(得分:1)

将当前项目的默认布局设为Relative

首先打开您的.xml文件,然后将constraint布局更改为relative布局。然后在打开项目的情况下转到Android Studio的顶层菜单。然后转到“窗口”选项卡,然后选择“将当前布局存储为默认值”。如果默认不是您喜欢的,请下载默认布局并将其设置为默认布局。

为所有项目制作Relative的默认布局

只需修改android studio资源中的模板布局文件

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

现在编辑此文件simple.xml.ftl并根据您的选择更改布局(注意。,以使默认相对只是复制到simple.xml.ftl文件中的代码下方),请注意一些布局需要额外的元素(例如LinearLayout需要android:orientation),在Android Studio中保存文件和创建活动,它应该可以工作。

<?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 :(得分:1)

请记住,如果修改simple.xml,android studio updater将检测到冲突并阻止应用更新。保留副本:)

答案 2 :(得分:0)

非常简单 - 只需3个步骤

  1. 转到C:\Program Files\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout
  2. 备份simple.xml.ftl
  3. Modify simple.xml.ftl到下面的代码并保存
  4. <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/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Sample"
        android:textSize="16sp" />
    </RelativeLayout>
    

    Windows 10 build:gradle:3.0.1

    上进行了测试
    • 适用于同一项目中的每项新活动以及未来的项目。
    • 注意:需要使用管理员权限修改simple.xml.ftl文件
    • 为此,layout > New > Edit File Templates... layoutResourceFile layoutResourceFile_vertical${ROOT_TAG}删除selected.settings - ,因为我已经尝试了但不是不行。
相关问题