Max Asura
Max Asura

Reputation: 821

aspect-ratio imageview

![enter image description here][1]I'm going to be insane with this problem. I can't fix aspect-ratio on an image. I tried with gravity and matrix but does not keep aspect-ratio. How I can resolve? I've a variable text in textview (from an array) and I'd like have a fixed image.

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

 <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:orientation="vertical" >

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/luna1"
    android:textSize="15pt" 
    android:layout_weight="1"/>

<ScrollView
    android:id="@+id/scrollView10"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:background="#000000"
    android:layout_weight="1" >

    <TextView
        android:id="@+id/textView10"
        android:layout_width="match_parent"
        android:layout_height="320dp"
        android:background="#000000"
        android:gravity="center"
        android:textColor="#ffffff"
        android:textSize="14sp"
               android:text="jjkjkljkjkldjklsdfjkljklsdfjklsdfjklsdfjklsdfjklsdfjklsdfjklfjlsdfjkl"
        android:autoLink="web|email"
        android:textStyle="italic" />
</ScrollView>
</LinearLayout>

<Button
android:id="@+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />

</LinearLayout>

Upvotes: 0

Views: 601

Answers (1)

kabuko
kabuko

Reputation: 36302

You're looking for scaleType. Set the scaleType to something like centerCrop or centerInside and your aspect ratio will be maintained.

Update:

Also make sure you're using src for setting your image and not background.

Upvotes: 1

Related Questions