Reputation: 3248
I am trying to place an image with a label below the image, I have been trying a lot but couldn't prevent the image and text from overlapping, Here is my layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >
<ImageView
android:id="@+id/grid_item_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="15dp"
android:paddingLeft="15dp"/>
<TextView
android:id="@+id/grid_item_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:singleLine="true"
android:layout_marginLeft="20dp"
android:paddingLeft="15dp"
android:textSize="20dp">
</TextView>
Upvotes: 0
Views: 6055
Reputation: 4689
You can simplify your layout by using the textview's compound drawable.
Remove your image view and set a drawableTop to your text view like this :
<TextView
android:id="@+id/grid_item_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
android:text="My Text"
android:drawableTop="@drawable/my_drawable"/>
You can also set a drawable in java code using the setCompoundDrawable methods
More on this topic in this blog post.
Upvotes: 6
Reputation: 3017
add this into your TextView
android:layout_below="@+id/grid_item_image"
and remove the android:gravity="center"
from TextView
Upvotes: 3