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?
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 . true but there what is the cause of it and how to get it created automatically when the project is created.
To create another dimens. xml file, right click your res folder and choose New > Value resource file. Then write in dimens and choose Smallest Screen Width. Write in 600 for the width (7” tablet).
dimens. xml is used for defining the dimensions for different widgets to be included in the Android project. It is a good coding practice to use dimens.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With