Android Studio2.3更换默认的ConstraintLayout布局

    最近Google更新了AS为2.3版本,由于现在大力推行ConstraintLayout布局,所以在新建工程的时候默认的布局也会变为ConstraintLayout,其实ConstraintLayout用起来还是蛮方便的,详见郭霖老师的文章http://blog.csdn.net/guolin_blog/article/details/53122387 。 但是,如果我们仅仅想写一个Demo用ConstraintLayout难免有点大材小用,操作起来也不如直接配置xml文件那么简单。那么Android Studio能否修改新建工程的默认布局呢?非常遗憾在setting里面暂时是无法实现的,但是我们可以通过修改默认布局的文件来达到我们的目的。

    以下以将ConstraintLayout修改为LinearLayout为例,介绍以下修改方法,其他的举一反三即可。

    首先打开你的Android Sudio安装目录,我的为E:\ProgramFile\soft\Android\AndroidStudio,进入到以下文件夹\plugins\android\lib\templates\activities\common\root\res\layout,如图所示:




 然后使用文本编辑器打开simple.xml.ftl文件:如下图


``` ```

```

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
<#if hasAppBar && appBarLayoutName??>
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/${appBarLayoutName}"
</#if>
    tools:context="${packageName}.${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!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</#if>
</android.support.constraint.ConstraintLayout>

```

   是不是很熟悉?没错这就是 ConstraintLayout 的布局文件,只不过有一些条件判定,我们无视它,直接改成RelativeLayout的布局代码

<RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}">


    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


</RelativeLayout>

然后保存即可。注意:为了防止错误操作以及方便日后还原,最好在修改前备份一下simple.xml.ftl文件。

现在,再重新打开AS,新建一个工程,默认的布局就变成了RelativeLayout了,是不是很简单呢?



参考文档




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值