dev-x
dev-x

Reputation: 899

There is no dimens.xml in android studio project

I have installed Android Studio 2.2.2 on my laptop. Then I updated it recently. But when I create an empty project, there is no dimens.xml on the project. Whereas when I used Android Studio 2.2.2 there is a dimens directory (with 2 dimens.xml). What happen to my Android Studio?

Upvotes: 18

Views: 38738

Answers (1)

zsmb13
zsmb13

Reputation: 89578

Your Android Studio is fine. From 2.3, the default Activity layout templates have a ConstraintLayout as their root element with no margins applied to it. In the old templates, this used to be a RelativeLayout with its margins set as resource values in dimens.xml. Since these values are no longer in the default layout file, an empty dimens.xml is not created in the project by default.

If you need a dimens.xml, you can just create one under the res/values folder with New -> Values resource file.


For reference, the old default layout that used dimens resources:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.package.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

</LinearLayout>

And the new default that doesn't:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.package.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Upvotes: 24

Related Questions