2

Trying to figure out to overcome this little problem.

Below, on the left side, is a sample of the view that I'm trying to implement for an app. On the right side is the view that I'm ending up with. Container

In my xml mock up I've decided to use a RelativeLayout but I can't get the TextView to be centered between the top and bottom views.

For reference here's a represenation of my xml code:

 <RelativeLayout 
    android:layout_width:"match_parent"
    android:layout_height:"wrap_content">
    <ImageView
        android:id="@+id/BlackImage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:layout_alightParentTop="true"
        android:layout_centerHorizontal="true"/>
    <ImageView
        android:id="@+id/RedImage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:layout_below="@+id/BlackImage"
        android:layout_centerHorizontal="true"/>
    <TextView
        android:id="@+id/TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/BlackImage"
        android:layout_centerHorizontal="true"/>
 </RelativeLayout>

Any idea what I'm missing, or how to change to get what I want?

edc598
  • 317
  • 3
  • 11
  • 1
    I think I'd try a `FrameLayout` for that, because the `RelativeLayout` is rather used for views that are aligned along their edges. Anyhow, you could try a negative margin or padding. – Trinimon May 17 '13 at 19:23
  • try below link hope it will help you :- – duggu May 17 '13 at 19:23

1 Answers1

0

try below link hope it will help you :-

TextView above Image view in a layout

Android listview item display text over image using array adapter

how to put text under image view

 <?xml version="1.0" encoding="utf-8"?> 
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" android:background="@drawable/tmp" >


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/uph" 
             android:layout_marginTop="-10dp"/>

        <RelativeLayout  android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_gravity="top|center">

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/propfile" 
            />

           <TextView  android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:text="text" 
               android:layout_centerInParent="true"
           /> 
      </RelativeLayout>   
    </LinearLayout>
Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113
  • Didn't know I could have multiple options for `layout_gravity`. You learn something new everyday! Gonna try this out, thanks for the link! – edc598 May 17 '13 at 20:03