[英]There is no dimens.xml in android studio project
I have installed Android Studio 2.2.2 on my laptop. 我已经在笔记本电脑上安装了Android Studio 2.2.2。 Then I updated it recently.
然后我最近更新了它。 But when I create an empty project, there is no dimens.xml on the project.
但是,当我创建一个空项目时,该项目上没有dimens.xml。 Whereas when I used Android Studio 2.2.2 there is a dimens directory (with 2 dimens.xml).
而当我使用Android Studio 2.2.2时,有一个dimens目录(带有2 dimens.xml)。 What happen to my Android Studio?
我的Android Studio会怎样?
Your Android Studio is fine. 您的Android Studio很好。 From 2.3, the default Activity layout templates have a
ConstraintLayout
as their root element with no margins applied to it. 从2.3开始,默认的活动布局模板将
ConstraintLayout
作为其根元素,并且未应用任何边距。 In the old templates, this used to be a RelativeLayout
with its margins set as resource values in dimens.xml
. 在旧模板中,它以前是
RelativeLayout
,其边距设置为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. 由于这些值不再位于默认布局文件中,因此默认情况下不会在项目中创建一个空的
dimens.xml
。
If you need a dimens.xml
, you can just create one under the res/values
folder with New -> Values resource file
. 如果需要
dimens.xml
,则可以使用“ New -> Values resource file
在res/values
文件夹下创建一个dimens.xml
。
For reference, the old default layout that used dimens
resources: 作为参考,旧的默认布局使用了
dimens
资源:
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.