我已在我的笔记本电脑上安装了Android Studio 2.2.2。然后最近更新了它。但是当我创建一个空项目时,项目中没有dimens.xml文件。而当我使用Android Studio 2.2.2时,有一个dimens目录(带有2个dimens.xml文件)。我的Android Studio出了什么问题?
我已在我的笔记本电脑上安装了Android Studio 2.2.2。然后最近更新了它。但是当我创建一个空项目时,项目中没有dimens.xml文件。而当我使用Android Studio 2.2.2时,有一个dimens目录(带有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>
dimens.xml
。 - zsmb13
values
文件夹中自己创建它。 - miljon