自动添加Gradle中的ConstraintLayout依赖项

自动添加Gradle中的ConstraintLayout依赖项

本文介绍了自动添加Gradle中的ConstraintLayout依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要我更新了我的工作室(版本2.3)并构建了版本('25.0.0')

constraintlayout 依赖关系 build.gradle 文件。



和布局渲染为父 ConstraintLayout ,任何人都可以知道如何在创建活动时去除这种依赖关系。



在活动创建gradle代码之前。

 依赖关系{
compile'c​​om.android.support:support-v4:23.2.1'
}

在活动创建gradle代码之后。

  dependencies {
compile'c​​om.android.support:support-v4:23.2.1'
compile'c​​om.android.support.constraint:constraint-layout:1.0.0'$您可以修改默认的模板布局文件。 在Android Studio资源,路径:

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

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



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

  <?xml version =1.0encoding =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 =@
android:paddingRight =@ dimen / activity_horizo​​ntal_margin
android:paddingTop =@ dimen / activity_vertical_margin
android:paddingBottom =@ dimen / activity_vertical_margin
< #if hasAppBar&& appBarLayoutName ??>
app:layout_behavior =@ string / appbar_scrolling_view_behavior
工具:showIn =@ layout / $ {appBarLayoutName}
< /#if>
tools:context =$ {relativePackage}。$ {activityClass}>

< 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>


Just I update my studio (version 2.3) and build version ('25.0.0'),

now, when i try to create new activity then automatically constraintlayout dependency added in my build.gradle file.

and layout render as parent ConstraintLayout, can anyone know how to remove this dependency when activity is created.

Before activity creation gradle code.

dependencies {
  compile 'com.android.support:support-v4:23.2.1'
}

After activity creation gradle code.

dependencies {
  compile 'com.android.support:support-v4:23.2.1'
  compile 'com.android.support.constraint:constraint-layout:1.0.0'
}
解决方案

You can modify default template layout file in Android Studio resources, path to it:

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

Edit file simple.xml.ftl and change layout to your choice, notice that some layouts require additional elements (e. g. LinearLayout needs android:orientation), save file and create activity in Android Studio, it should work.

Mine looks like this (I have 2.2.3 so I have 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>

这篇关于自动添加Gradle中的ConstraintLayout依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:22