[英]There is no dimens.xml in android studio project
我已經在筆記本電腦上安裝了Android Studio 2.2.2。 然后我最近更新了它。 但是,當我創建一個空項目時,該項目上沒有dimens.xml。 而當我使用Android Studio 2.2.2時,有一個dimens目錄(帶有2 dimens.xml)。 我的Android Studio會怎樣?
您的Android Studio很好。 從2.3開始,默認的活動布局模板將ConstraintLayout
作為其根元素,並且未應用任何邊距。 在舊模板中,它以前是RelativeLayout
,其邊距設置為dimens.xml
資源值。 由於這些值不再位於默認布局文件中,因此默認情況下不會在項目中創建一個空的dimens.xml
。
如果需要dimens.xml
,則可以使用“ New -> Values resource file
在res/values
文件夾下創建一個dimens.xml
。
作為參考,舊的默認布局使用了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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.