2017-08-30 68 views
-3

我是Android Studio新手。我在@dimen出現錯誤,我不知道如何解決它。@dimen上的錯誤

下面的代碼:

<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.videotest.MainActivity">

+1

也許不存在?添加堆棧跟蹤 – Yoni

+3

你沒有顯示代碼,你沒有顯示錯誤 - 我們應該如何幫助你沒有適當的上下文?包括所有相關詳細信息以獲得更快和/或更高質量的幫助。 –

回答

1

你必須定義尺寸您在dimens.xml中通過@dimen進行設置。

根據Android Docs的說法,「維度是一個簡單的資源,它使用name屬性中提供的值(而不是XML文件的名稱)引用,因此可以將維度資源與其他簡單資源在一個XML文件中,在一個元素下。「

從Android文檔,dimens.xml的例子:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
Copyright 2013 The Android Open Source Project 

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. 
--> 

<resources> 
    <dimen name="action_button_min_width">56dp</dimen> 
    <dimen name="indeterminate_progress_size">32dp</dimen> 
</resources> 

這裏定義你的其他尺寸並儲存values目錄下這個XML。也請看看這個答案解釋when to use the dimens.xml file in Android?

2

所有@dimen首先指的維度,它就是你定義維度,從任何佈局文件中使用它們的文件。

在您的項目結構中,轉至目錄app/src/main/res/values/ 現在檢查是否存在dimens.xml文件。

如果沒有,然後創建一個名爲dimens.xml一個新的資源文件

所以根據填充你要定義夢詩是這樣的:

<resources> 
<!-- Default screen margins, per the Android Design guidelines. --> 
<dimen name="activity_horizontal_margin">16dp</dimen> 
<dimen name="activity_vertical_margin">16dp</dimen> 
</resources>