Can not put ViewAnimator above a button in RelativeLayout

86 Views Asked by At

I am trying to put a ViewAnimator above a button in RelativeLayout but it does not let me. Here is the 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">
<ViewAnimator
        android:id="@+id/show_picture_animator_VA"
        android:layout_alignParentTop="true"
        android:layout_above="@id/show_picture_hold_BTN"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

</ViewAnimator>
<Button android:id="@+id/show_picture_hold_BTN"
        android:text="HOLD"
        android:textColor="#000000"
        android:background="@drawable/hold_button_shape"
        android:layout_width="@dimen/show_picture_hold_button_widht"
        android:layout_height="@dimen/show_picture_hold_button_height"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>

This gives me this error: Error:(7, -1) android-apt-compiler: [] --\res\layout\show_picture.xml:7: error: Error: No resource found that matches the given name (at 'layout_above' with value '@id/show_picture_hold_BTN').

Can someone please help me :)

1

There are 1 best solutions below

0
Jon Adams On

Ids are added in the order they are listed (the ones with the @+id values). show_picture_hold_BTN is defined (android:id="@+id/show_picture_hold_BTN") after it as referenced in the ViewAnimator.

Since this is a relative layout, the align values are what order them visually; swap the order of the two views in XML and you're good.

<Button
    android:id="@+id/show_picture_hold_BTN"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="HOLD"
    android:textColor="#000000" />

<ViewAnimator
    android:id="@+id/show_picture_animator_VA"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/show_picture_hold_BTN"
    android:layout_alignParentTop="true">
</ViewAnimator>