Daniele
Daniele

Reputation: 4343

XML - android:layout_above Error

I'm building an App in Android Studio.

I've built a simple Splash Screen to launch it while my MainActivity is loading and to give my App a more professional look. This is my XML code:

<?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>

The problem is that when I try to build my App I get the following error which seems to be caused by android:layout_above="@id/designerTextView":

No resource found that matches the given name (at 'layout_above' with value '@id/designerTextView').

I can't figure out what the problem is, since I've given the right id to my second TextView.

I'd appreciate some help.

Upvotes: 1

Views: 357

Answers (2)

Sairam
Sairam

Reputation: 169

use this it is working I tested it.

<?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="@mipmap/ic_launcher"/>

    <TextView
        android:id="@+id/designerTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:text="hai"
        android:layout_alignBottom="@id/splashscreen"
        android:textColor="#9E9E9E"/>
    <TextView
        android:id="@+id/developerTextView"
        android:layout_width="match_parent"
        android:textAlignment="center"
        android:layout_height="wrap_content"
        android:text="hello"
        android:layout_above="@id/designerTextView"
        android:textColor="#9E9E9E"/>

</RelativeLayout>

Upvotes: 0

Eugen Martynov
Eugen Martynov

Reputation: 20140

That is quite easy to explain. You have text view which is referring id that was not defined before @id/designerTextView. This id is defined later with next code:

 <TextView
        android:id="@+id/designerTextView"
 ....
 />

To fix it place symbol + in first place where you refer this id and remove it in the second definition:

  <TextView
        android:id="@+id/developerTextView"
        android:layout_above="@+id/designerTextView"
  .....
  />

  <TextView
        android:id="@id/designerTextView"
        android:layout_alignBottom="@id/splashscreen"
  .....
  />

Read more info here Difference between "@id/" and "@+id/" in Android

Upvotes: 1

Related Questions