3

ConstraintLayout依赖只是更新我的工作室(版本2.3)并建立版本('25 .0.0' )自动加入gradle这个

现在,当我尝试将自动创建新的活动constraintlayoutdependency添加在我的build.gradle文件中。

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

在活动创建gradle代码之前。

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

创建活动的gradle代码后。

dependencies { 
    compile 'com.android.support:support-v4:23.2.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.0' 
} 
+0

创建空的活动(新建 - >活动 - >空活动)如果你不想'ConstraintLayout'。 – Spartan

回答

4

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

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

编辑文件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> 
+0

我正在使用Linux ubuntu –

+0

原理将simlar,去Android Studio文件夹到我写的路径或搜索文件'simple.xml.ftl' – miljon

+0

这是工作,但你给了一半的答案,我做了什么,然后自动gradle依赖将不会添加 –