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依賴將不會添加 –