4

I've a textview and a view, I Want to show the textview above the view, It's working well, But when adding elevation to the View, the TextView is hidden under that view .

XML :

<View
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:layout_margin="10dp"
    android:elevation="2dp"
    android:background="#ffffffff"
    android:id="@+id/view" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:id="@+id/textView"
    android:layout_alignTop="@+id/view"
    android:layout_toRightOf="@+id/view"
    android:layout_toEndOf="@+id/view" />
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Jaeger
  • 1,646
  • 8
  • 27
  • 59

1 Answers1

3

Use Framelayout for this purpose, You have to remove android:background="#ffffffff" because of that you were not getting your elevation and it was hiding textview

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dp">

<View
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:elevation="2dp"
    android:scaleType="center" />

<TextView
    android:id="@+id/textView"
    android:layout_width="100dp"
    android:layout_height="50dp"
    android:layout_gravity="center_horizontal|bottom"
    android:layout_marginBottom="20dip"
    android:background="#AA000000"
    android:gravity="center"
    android:text="New Text"
    android:textColor="#ffffffff"
    android:textSize="18dp" />

Check elevation issue

Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142