Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically added ConstraintLayout dependency in gradle

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'
}
like image 927
Yogesh Rathi Avatar asked Mar 14 '17 06:03

Yogesh Rathi


2 Answers

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>
like image 116
miljon Avatar answered Oct 01 '22 14:10

miljon


latest Android support Constraint layout automatically if still you are not able to use than in build.gradle file add this dependency implementation 'com.android.support.constraint:constraint-layout:1.1.3'

like image 41
Monika Mishra Avatar answered Oct 01 '22 13:10

Monika Mishra