1

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.

Daniele
  • 4,163
  • 7
  • 44
  • 95
  • move `developerTextView` after `designerTextView` – Blackbelt Jun 24 '16 at 14:03
  • Not it, tried it myself. :D Had the same idea. I think you need to remove `android:orientation="vertical"` since Relative Layout does not have it. That's the only thing I can see at the moment. Btw copying these 2 TextView's in my Relative layout actually doesn't cause any errors. – Vucko Jun 24 '16 at 14:05
  • As far as I can see, you're also missing `xmlns:tools="http://schemas.android.com/tools"` and `tools:context=".MainActivity"` – Vucko Jun 24 '16 at 14:08
  • @Blackbelt moving developerTextView after designerTextView solved the problem. But why is that happening? – Daniele Jun 24 '16 at 14:11
  • It is simple. Look for the difference between @id and @+id – Blackbelt Jun 24 '16 at 14:12
  • @Blackbelt how do you explain it working for me in the opposite direction? **[I know the difference between @ id and @+id]** – Vucko Jun 24 '16 at 14:13
  • @Vucko mostly you have declared the same id in another file – Blackbelt Jun 24 '16 at 14:19

2 Answers2

1

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

Community
  • 1
  • 1
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
0

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>
Sairam
  • 169
  • 12