所以,我想下面的代碼收到錯誤
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.slidenerd.sample.customdesign.MainActivity"
android:background="#252525">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/clock"
android:layout_above="@id/textView"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="0:00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textColor="#616161"
android:textSize="100sp"
android:layout_centerInParent="true" />
<ToggleButton
android:text="ToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="54dp"
android:id="@+id/toggleButton"
android:background="@drawable/toggle_selector"
android:textOff=""
android:textOn=""/>
</RelativeLayout>
我得到的錯誤是這些
Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
E:\AndroidProjects\Tutorials\CustomDesign\app\src\main\res\layout\activity_main.xml
Error:(17, 31) No resource found that matches the given name (at 'layout_above' with value '@id/textView').
E:\AndroidProjects\Tutorials\CustomDesign\app\build\intermediates\res\merged\debug\layout\activity_main.xml
Error:(17, 31) No resource found that matches the given name (at 'layout_above' with value '@id/textView').
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
Information:BUILD FAILED
Information:Total time: 21.791 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console
相比之下以下工作正常
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.slidenerd.sample.customdesign.MainActivity"
android:background="#252525">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/clock"
android:layout_marginTop="54dp"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="0:00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageView"
android:id="@+id/textView"
android:textColor="#616161"
android:textSize="100sp"
android:layout_centerInParent="true" />
<ToggleButton
android:text="ToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="54dp"
android:id="@+id/toggleButton"
android:background="@drawable/toggle_selector"
android:textOff=""
android:textOn=""/>
</RelativeLayout>
我不明白爲什麼第一個不起作用。根據位於佈局中心的項目排列各種項目是否錯誤?