我在笔记本电脑上安装了Android Studio 2.2.2。然后我最近更新了它。但是当我创建一个空项目时,项目上没有dimens.xml。而当我使用Android Studio 2.2.2时,有一个维度目录(使用2 dimens.xml)。我的Android Studio会发生什么?
我在笔记本电脑上安装了Android Studio 2.2.2。然后我最近更新了它。但是当我创建一个空项目时,项目上没有dimens.xml。而当我使用Android Studio 2.2.2时,有一个维度目录(使用2 dimens.xml)。我的Android Studio会发生什么?
你的Android Studio很好。从2.3开始,默认的Activity布局模板有一个 ConstraintLayout
作为根元素,没有应用边距。在旧模板中,这曾经是一个 RelativeLayout
将其边距设置为资源值 dimens.xml
。由于这些值不再位于默认布局文件中,因此为空 dimens.xml
默认情况下不在项目中创建。
如果你需要一个 dimens.xml
,你可以在下面创建一个 res/values
文件夹 New -> Values resource file
。
供参考,使用旧的默认布局 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>
并且没有的新默认值:
<?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>