How to make view align at the bottom

Viewed 468

Supposed that I have the following screen layout: enter image description here

I have an AdView at the bottom of the page. I also have a floating button just above it. The whole layout is in RelativeLayout. When I set the AdView to GONE, the floating button is nowhere to be found. I set the layout parameters of the floating button to be above the AdView and is alignParentRight. What is the best thing to do to make sure that the floating button remains in the right bottom corner of the screen even after setting the visibility of AdView to GONE?

If I put the two views inside a LinearLayout, the result will be this one: enter image description here

Here's the XML code:

<LinearLayout
        android:id="@+id/cpnt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@color/alkitabfeedback_step_pager_selected_tab_color"
        android:orientation="vertical">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_play_audio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_alignParentRight="false"

            android:layout_gravity="right"
            android:layout_margin="10dp"
            android:src="@drawable/ic_fab_audio"
            android:visibility="visible" />

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="false"
            android:background="@android:color/white"
            android:visibility="visible"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/ad_unit_id" />
    </LinearLayout>
4 Answers
Related