Warm tip: This article is reproduced from stackoverflow.com, please click
android android-layout xamarin

Is something wrong with my layout code using RelativeLayout in xamrin android?

发布于 2020-03-27 10:23:21

This layout has three controls:two toolbars and a framelayout.I want two toolbars one at the bottom of the layout and another at the top of the layout.The framelayout just lies between them.I have the code like this,but it always has the error saying "No resource found that matches the given name (at 'layout_above' with value '@id/bottomToolBar')".I'm pretty sure I have set the ID of the bottom toolBar. I am so desperate. Many thanks in advance.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
    android:id="@+id/mainToolBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:titleTextColor="#FFFFFF"
    app:title="Musics">
</android.support.v7.widget.Toolbar>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/mainToolBar"
    android:layout_above="@id/bottomToolBar"
    android:id="@+id/fragmentsContainer"
    />

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:id="@+id/bottomToolBar"
    android:minHeight="?attr/actionBarSize"
    android:background="#EFEFEF">
</android.support.v7.widget.Toolbar>
</RelativeLayout>
Questioner
Liu Feng
Viewed
155
Alexander Hoffmann 2019-07-03 22:30

Yes. When your FrameLayout is parsed the parser tries to resolve all the IDs. So it also tries to look up bottomToolBar. However, at this point, bottomToolBar does not exist in your R.java / Resource.cs file and therefore can't be found. This ID is created later in your second Toolbar in this line:

android:id="@+id/bottomToolBar"

The + indicates, that a new id must be created if no id exists for this reference. It will then be added to your R.java file or Resource.cs file for Xamarin.

So the fix would be: Add a + to your reference from FrameLayout to bottomToolBar, so that an id for bottomToolBar is created when you try to reference it:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/mainToolBar"
    android:layout_above="@+id/bottomToolBar"
    android:id="@+id/fragmentsContainer"
    />

Source: https://developer.android.com/guide/topics/ui/declaring-layout#id