1
votes

I have an ImageView with a bitmap drawable. There are different versions of the bitmap for each device density (hdpi, xhdpi, xxhdpi etc).

I want to position a TextView on top of the ImageView, and relative to the ImageView's position. e.g. 30px from the right, 50px from the top. The TextView needs to always be displayed in a certain part of the image, so its position will be different for each version of the image created for different screen densities.

Positioning with pixels seems to work. I'm able to create different XML layout files with pixel values for the different versions of the image (hdpi, xhdpi, etc). However, I'm not able to specify px units in dimen.xml

Is positioning with pixels the correct method here? Will positioning with pixels relative to the image work across different devices?

1
can you please explain more what certain part of image ?Haresh Chhelana
The text needs to always fit inside a shape which is part of the image.Simian

1 Answers

1
votes

I would do it like this. Place a RelativeLayout above your ImageView and set its color to `#66cccccc. And put a TextView in it.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:src="@drawable/yourImage" />

 <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="25dp"
        android:background="#66cccccc">

        <TextView
         android:id="@+id/textView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="#fff"
         android:text="Test Description" />

    </RelativeLayout>


</RelativeLayout>