2

I need some help with android layout

Here is a imageView

<ImageView
    android:id="@+id/fragment_user_profile_avatar"
    android:layout_width="match_parent"
    android:layout_height="305dp"
    android:scaleType="centerCrop"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@color/feed_bg" />

And the textView on ImageView

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/user_name"
    android:textColor="#ffffffff"
    android:textSize="28sp"
    android:fontFamily="roboto-regular"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

It all under one RelativeLayout. When i'm trying to set imageView's elevation, textView is hiding under the imageView.

Thanks in advance!

Francisco Noriega
  • 13,725
  • 11
  • 47
  • 72
dennes544
  • 256
  • 3
  • 18

2 Answers2

2

Use android:elevation on your TextView with number higher than that on your ImageView i.e as below

<ImageView
    android:elevation="5dp"
    android:id="@+id/fragment_user_profile_avatar"
    android:layout_width="match_parent"
    android:layout_height="305dp"
    android:scaleType="centerCrop"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@color/feed_bg" />

<TextView
    android:elevation="6dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/user_name"
    android:text="Hello This is a TextView"
    android:textColor="#ffffffff"
    android:textSize="28sp"
    android:fontFamily="roboto-regular"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
Nishant Srivastava
  • 4,723
  • 2
  • 24
  • 35
  • Your answer may be better than mine, I've never used elevation before. I checked out the documentation before following through with my post, and it sounded like it adds shadows, which may or may not be desirable. And that might not always be the case, I don't know. – Joey Harwood Apr 13 '15 at 16:38
  • okay, but my textview gets and elevation too in this case, and i dont need elevation on textview – dennes544 Apr 13 '15 at 16:43
  • Sorry, my fault. i didnt check it. It works perfectly! Big thanks to you! – dennes544 Apr 13 '15 at 16:51
0

The relative position in an xml layout is decided by the order in the file. If you first create the ImageView and then the TextView. It should appear as you want.

<RelativeLayout...>

<ImageView
     android:id="@+id/fragment_user_profile_avatar"
     android:layout_width="match_parent"
     android:layout_height="305dp"
     android:scaleType="centerCrop"
     android:layout_alignParentTop="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentStart="true"
     android:background="@color/feed_bg" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/user_name"
    android:textColor="#ffffffff"
    android:textSize="28sp"
    android:fontFamily="roboto-regular"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>
Joey Harwood
  • 961
  • 1
  • 17
  • 27