android studio项目中没有dimens.xml

Rie*_*ana 14 android android-studio

我在笔记本电脑上安装了Android Studio 2.2.2.然后我最近更新了它.但是当我创建一个空项目时,项目中没有dimens.xml.而当我使用Android Studio 2.2.2时,有一个维度目录(带有2个dimens.xml).我的Android Studio会发生什么?

zsm*_*b13 19

你的Android Studio很好.从2.3开始,默认的Activity布局模板将一个ConstraintLayoutas作为其根元素,并且没有应用任何边距.在旧模板中,以前将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>
Run Code Online (Sandbox Code Playgroud)

并且没有的新默认值:

<?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>
Run Code Online (Sandbox Code Playgroud)

  • 有没有关于这个的官方文档? (2认同)