1

I need to set a TextView exactly specific part of the photo I am using from bellow xml but i set all of size manual I need to be dynamic for different size mobile:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/list_back" />

    <TextView
        android:id="@+id/CallCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/background_dark"
        android:textStyle="bold" />
</RelativeLayout>

enter image description here

3 Answers3

1

Have you tried with a frameLayout ? set the gravity to right | top and it should work on every device

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/CallCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="test"
        android:textSize="20sp"
        android:textColor="@android:color/background_dark"
        android:textStyle="bold"
        android:layout_gravity="right|top" />

</FrameLayout>
David Seroussi
  • 1,650
  • 2
  • 17
  • 34
0

If you need to use RelativeLayout as root, you can use layout_alignParentX properties.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/list_back" />

    <TextView
        android:id="@+id/CallCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:textColor="@android:color/background_dark"
        android:textStyle="bold" />
</RelativeLayout>

But if you don't need, I recommend to use a FrameLayout as root to avoid a double call to invalidate() from RelativeLayout.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/CallCenter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|end"
        android:text="test"
        android:textSize="20sp"
        android:textColor="@android:color/background_dark"
        android:textStyle="bold" />
</FrameLayout>
Giorgio Antonioli
  • 15,771
  • 10
  • 45
  • 70
0

I resolve my problem :

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
    android:src="@drawable/list_back" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <View
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <TextView
        android:id="@+id/CallCenter"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:paddingLeft="5dp"
        android:paddingRight="15dp"
        android:layout_weight="3"
        android:textColor="@android:color/background_dark"
        android:textStyle="bold" />
</LinearLayout>