Mohammad Ersan
Mohammad Ersan

Reputation: 12444

RelativeLayout, Unable to resolve id

i was trying to layout views within RelativeLayout like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:text="TextView" android:id="@+id/upperView"
        android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/bottomView"></TextView>
    <TextView android:text="TextView" android:id="@+id/bottomView"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</RelativeLayout>

and this id is not recognized by android:

 android:layout_below="@id/bottomView"

because i defined the @+id/bottomView" after its call, but sometimes the sort matter to draw who over who, i can solve it from the code, but how fix it within XML

Upvotes: 2

Views: 3502

Answers (4)

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

i solved it, just add + before id keyword in your layout xml

Upvotes: 1

Zwiebel
Zwiebel

Reputation: 1615

You need to first create bottomView, and then use the layout_below, because android / java create things in the order, what in you made them. Hope it helps.

Upvotes: 0

NguyenDat
NguyenDat

Reputation: 4159

In your layout when define:

@+id/bottomView"

The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file)

When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace (Ref.1)

So, change your xml layout like that:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView 
        android:text="DownTextView" 
        android:id="@+id/upperView"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/bottomView">
    </TextView>
    <TextView 
        android:text="UpTextView" 
        android:id="@id/bottomView"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
</RelativeLayout>

Reference:1 Android Layout ID Document

Upvotes: 7

Nikola Despotoski
Nikola Despotoski

Reputation: 50538

How can you do upper view to be below bottom view, logically is inconsistent to me?

You should do otherwise. In the bottomview you add android:layout_below="@id/upperview"

Since bottom is below something.

Upvotes: 0

Related Questions