0

I am getting compilation error in axml where I have referenced the item before declaring it.

As far as I know, Android doesn't have any such constraints. Moreover if I copy paste the same layout in Android studio it works fine.

Does anyone know a workaround of this issue in Xamarin.Android

The error is:

error APT0000: No resource found that matches the given name (at 'layout_below' with value '@id/textView1').

Here is a simplified version of layout to generate the error:

<?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"
    android:minWidth="25px"
    android:minHeight="25px">
    <Button
        android:id="@+id/button1"
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/textView1" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Hello World" />
</RelativeLayout>
gmtek
  • 741
  • 3
  • 7
  • 25
  • To add onto @Daniel P's answer, XML is parsed sequentially (top->down) and thus the first time you refer to an ID you need to include the `@+id` prefix so a new resource id is generated. You could work around this same scenario by ensuring all views have resource ids in a sequential manner (such as moving your `Button` view XML below your `TextView` view XML). You can be a bit liberal with your usage of `@+id` as the `aapt` tooling is smart enough to know if the resource id already exists or not. https://stackoverflow.com/a/6646113/1048571 – Jon Douglas Aug 14 '18 at 20:40

1 Answers1

2

You need to add a + in front of the id the very first time it is used. So in this case it should look like:

android:layout_below="@+id/textView1"

Here is a similar question: No resource found that matches the given name

Daniel P
  • 3,314
  • 1
  • 36
  • 38