ImageView scaleType doesn't work
Asked Answered
M

1

5

I have a ImageView which contains a little "?" as image. This image gets stretched and looks ugly. So I tried to set the ImageView.ScaleType-property to fitCenter but it doesn't have any effect. I tried all other scaleTypes too, but non of it affects my layout. Since the user will be able to upload a picture at any size in that ImageView later on, I want my ImageView to always fit it in the center. Here is my xml-file:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton"
            android:background="@android:drawable/ic_menu_save"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:hint="name of question"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
    </RelativeLayout>

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/imageViewQuestion"
        android:layout_gravity="center_horizontal"
        android:background="@android:drawable/ic_menu_help"
        android:layout_weight="1"
        android:cropToPadding="false"
        android:onClick="clickQuestion"
        android:scaleType="centerCrop" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textViewQuestion"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.11"
        android:textAlignment="center"
        android:hint="Question"
        android:onClick="clickQuestion"
        android:gravity="center" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.60">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="1"
            android:id="@+id/button1"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="2"
            android:id="@+id/button2"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="3"
            android:id="@+id/button3"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="4"
            android:id="@+id/button4"
            android:layout_weight="2"
            android:onClick="clickButtonEdit" />
    </LinearLayout>

</LinearLayout>

Does anyone see my mistake?

Motherly answered 11/3, 2015 at 16:5 Comment(0)
S
40

Try using src instead of background :

replace

android:background="@android:drawable/ic_menu_help"

by

android:src="@android:drawable/ic_menu_help"
Seed answered 11/3, 2015 at 16:9 Comment(2)
Your are welcome, please don't forget to mark it as answered so that the question can be closed ;)Seed
I will as soon as I can. ;-)Motherly

© 2022 - 2024 — McMap. All rights reserved.