您的位置:首页 > 移动开发 > Android开发

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

2017-05-08 15:01 537 查看
     最近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安装目录,我的为D:\Program Files\Android\Android Studio,进入到以下文件夹\plugins\android\lib\templates\activities\common\root\res\layout,如图所示:


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



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

[html]
view plain
copy

print?

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent">  
  
    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="Hello World!"  
    />  
  
  
</LinearLayout>  



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>

</LinearLayout>


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

现在,再重新打开AS,新建一个工程,默认的布局就变成了LinearLayout了,是不是很简单呢?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: