user1324936
user1324936

Reputation: 2187

Android Layout, scale width to screen resolution

I want to resize an image to fit to screen that it fills the complete width. The hight should be set in aspect ratio. For example the image dimentions are widthxheight 10x5 and the phone is 400 width. the image should be displayed in 200x400.

I played around with some settings android:scaleType="center" should be the correct setting according to documentation but seems to have no effect, android:scaleType="centerCrop" fits the hight and makes the width bigger than the screen.

heres my layout:

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


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

    <ImageView
        android:id="@+id/imageViewFrage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:padding="1dp"
        android:scaleType="centerCrop"
        android:src="@drawable/bg_striped_img" />
</LinearLayout>

</LinearLayout>

thanks alot

Upvotes: 0

Views: 3587

Answers (2)

Tam&#225;s Szincs&#225;k
Tam&#225;s Szincs&#225;k

Reputation: 1031

You should try android:scaleType="centerInside".

According to the documentation (http://developer.android.com/reference/android/widget/ImageView.ScaleType.html):

Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). The image is then centered in the view.

Upvotes: 1

Related Questions