我正在 Android Studio 中构建应用。
我构建了一个简单的启动画面,以便在我的 MainActivity 加载时启动它,并使我的应用程序看起来更专业。这是我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/splashscreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="@drawable/icon_verde_mela"/>
<TextView
android:id="@+id/developerTextView"
android:layout_width="match_parent"
android:textAlignment="center"
android:layout_height="wrap_content"
android:text="@string/developer"
android:layout_above="@id/designerTextView"
android:textColor="#9E9E9E"/>
<TextView
android:id="@+id/designerTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="@string/designer"
android:layout_alignBottom="@id/splashscreen"
android:textColor="#9E9E9E"/>
</RelativeLayout>
问题是,当我尝试构建我的应用程序时,出现以下错误,这似乎是由 android:layout_above="@id/designerTextView"
引起的:
找不到与给定名称匹配的资源(在“layout_above”中值为“@id/designerTextView”)。
我无法弄清楚问题出在哪里,因为我已经为我的第二个 TextView 提供了正确的 ID。
我会很感激一些帮助。
最佳答案
这很容易解释。您的 TextView 引用了 @id/designerTextView
之前未定义的 id
。此 id
稍后使用下一个代码定义:
<TextView
android:id="@+id/designerTextView"
....
/>
要修复它,请将符号 +
放在您引用此 id
的第一位,并在第二个定义中将其删除:
<TextView
android:id="@+id/developerTextView"
android:layout_above="@+id/designerTextView"
.....
/>
<TextView
android:id="@id/designerTextView"
android:layout_alignBottom="@id/splashscreen"
.....
/>
关于android - XML-安卓 :layout_above Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38015283/