在gradle中自动添加ConstraintLayout依赖项

Yog*_*thi 6 android gradle build-dependencies android-constraintlayout

只是我更新我的工作室(版本2.3)和构建版本('25 .0.0'),

现在,当我尝试创建新活动时,会自动constraintlayout dependency添加到我的build.gradle文件中.

和布局呈现为父级ConstraintLayout,任何人都可以知道如何在创建活动时删除此依赖项.

在活动创建gradle代码之前.

dependencies {
  compile 'com.android.support:support-v4:23.2.1'
}
Run Code Online (Sandbox Code Playgroud)

活动创建后gradle代码.

dependencies {
  compile 'com.android.support:support-v4:23.2.1'
  compile 'com.android.support.constraint:constraint-layout:1.0.0'
}
Run Code Online (Sandbox Code Playgroud)

mil*_*jon 5

您可以在Android Studio资源中修改默认模板布局文件,路径为:

C:\Program Files\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout
Run Code Online (Sandbox Code Playgroud)

编辑文件simple.xml.ftl并根据您的选择更改布局,注意一些布局需要其他元素(例如LinearLayout需求android:orientation),保存文件并在Android Studio中创建活动,它应该可以工作.

我看起来像这样(我有2.2.3所以我有RelativeLayout)

<?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>
Run Code Online (Sandbox Code Playgroud)

  • 需要更多调查 (2认同)