Exterminator13
Exterminator13

Reputation: 2182

How to stretch image to row height in layout?

There're text view and image in one row. I need to stretch image proportionally to be the same height as text view. How to do that?

That's layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/imageView1"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:adjustViewBounds="true"
    android:cropToPadding="true"
    android:src="@drawable/ic_launcher" />
</RelativeLayout>

Upvotes: 0

Views: 321

Answers (3)

Mihir Trivedi
Mihir Trivedi

Reputation: 1505

in your ImageView

Try this code

android:layout_alignBottom="@+id/textView1"

instead of

android:layout_centerVertical="true"

Upvotes: 2

Houcine
Houcine

Reputation: 24181

just use layout_alignTop and layout_alignBottom to align your views from Top and Bottom to have the same Height

Upvotes: 1

Nam Vu
Nam Vu

Reputation: 5725

try to use android:layout_weight. Weight can only be used in LinearLayout

Upvotes: 0

Related Questions