0

Well, I have a Container, an Image and some Texts (inside another container), this way:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:layout_margin="10dp"
    android:id="@+id/btn">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/background"
        android:src="@drawable/background"
        android:scaleType="centerCrop"/>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_left"
            android:layout_gravity="center_vertical" />

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                custom:fontStyle="bold"
                android:textSize="@dimen/textSizeSmall"
                android:text="Header" />

            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                custom:fontStyle="regular"
                android:textSize="@dimen/textSizeMicro"
                android:text="Body" />
        </LinearLayout>

    </LinearLayout>
</RelativeLayout>

The image associated with ImageView (yes, it is a background image) is bigger than the height of all text together. Thus, I would like to "crop" it inside RelativeLayout. But that ImageView always take full size when I set it to fill_parent. :(

What can I do?

P.S.: I already tried to use that image as background of RelativeLayout. Not working also.

Pleaaase, help!!

richardaum
  • 6,651
  • 12
  • 48
  • 64

2 Answers2

1

Use FrameLayout instead of RelativeLayout to get background image with same size of textview.

Edit

I've got answer here . You can do it with RelativeLayout by using layout_alignTop and layout_alignBottom. Sorry for my first wrong answer.

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

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/background"
        android:src="@drawable/background"
        android:scaleType="centerCrop"
        android:layout_alignTop="@+id/text_container"
        android:layout_alignBottom="@+id/text_container"/>

    <LinearLayout
        android:id="@+id/text_container"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left">

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Header" />

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Body" />
    </LinearLayout>
</RelativeLayout>

Hope it will be useful for you.

Community
  • 1
  • 1
Arkar Aung
  • 3,554
  • 1
  • 16
  • 25
-1

I find an answer here: https://stackoverflow.com/a/19405297/406110

Well, basically ImageView is aligned to top, bottom, left and right to the container with TextViews and heigth and width is k.

Community
  • 1
  • 1
richardaum
  • 6,651
  • 12
  • 48
  • 64