ConstraintLayout的取消使用 修改默认不是这个

来源:互联网 发布:青山长源软件 编辑:程序博客网 时间:2024/05/16 13:45

 最近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
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent">  
  7.   
  8.     <TextView  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:text="Hello World!"  
  12.     />  
  13.   
  14.   
  15. </LinearLayout>  

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

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


7 0