5

I have the following layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/create_workout_fab_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/fab"
android:stateListAnimator="@anim/fab_elevation"
android:clickable="true"
>

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/create_workout_fab_anim_helper"
    android:layout_width="@dimen/fab_size"
    android:layout_height="@dimen/fab_size"
    card_view:cardBackgroundColor="@color/primary_dark"
    card_view:cardCornerRadius="@dimen/fab_radius"
    android:visibility="invisible"
    />
<TextView
    android:id="@+id/create_workout_fab_label"
    android:layout_width="@dimen/fab_size"
    android:layout_height="@dimen/fab_size"
    android:background="@drawable/fab_ripple_selector"
    android:textAppearance="?android:textAppearanceLarge"
    android:text="+"
    android:textColor="@color/fab_label_color"
    android:duplicateParentState="true"
    android:gravity="center"
    tools:text="+"
    tools:textColor="@color/fab_label_color"
    />



    </FrameLayout>

The CardView is only there to use it for an smooth animation from a cirle button to a rectangle view by animation a radius change.

But the problem is, wheneever the CardView becomes visible it stays above the TextView. Why is that and how do I get it to lay under the TextView

SnafuBernd
  • 261
  • 4
  • 16

1 Answers1

6

FrameLayout draws children in order, first to last. Therefore you need to swap the CardView with the TextView.

UPDATE: Also if you are running on android L+ you need to set a higher elevation on the CardView than the TextView

Gil Julio
  • 812
  • 1
  • 9
  • 18
  • 2
    I tried it in bith orders in the xml layout. I also tried it within a RelativeLayout, still the CardView is always on top. – SnafuBernd Dec 10 '14 at 22:16
  • @Gil Julio, on L+ the trick is to add a higher elevation on the element supposed to be on top of the card, not on the card. – Flashbump Feb 12 '15 at 09:32