Search code examples
androidimageviewscrollviewscale

Imageview inside scrollview wont scale to actual img size


Tried about everything, why wont my imageview not scale to its actual proportions would be the question. I got it to crop and to squeeze. But idd like the text to wrap and the image to maitain its actual size.

Any help would be appreciated verry much.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fabview="http://schemas.android.com/apk/res-auto"
    android:id="@+id/RelativeLayout2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="200dp" >

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

            <TextView
                android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="20dp"
                android:text="text"
                android:textSize="15dp" />

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

                <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY" />
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="fill_parent"
        android:layout_height="185dp"
        android:layout_gravity="bottom"
        android:layout_weight="0"
        android:background="#cccccc" >

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="10dp"
            android:checked="false"
            android:text="RadioButton"
            android:textSize="15dp" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="0dp"
            android:checked="false"
            android:text="RadioButton"
            android:textSize="15dp" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="0dp"
            android:checked="false"
            android:text="RadioButton"
            android:textSize="15dp" />

        <RadioButton
            android:id="@+id/radio3"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="0dp"
            android:checked="false"
            android:text="RadioButton"
            android:textSize="15dp" />
    </RadioGroup>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginBottom="20sp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="85dp"
        android:background="@drawable/blue_button"
        android:text="@string/str_next"
        android:textColor="@drawable/blue_button_text"
        android:textSize="15dp" />

    <FrameLayout
        android:id="@+id/fab_target"
        android:layout_width="match_parent"
        android:layout_height="185dp"
        android:layout_gravity="center_horizontal|bottom|right" />

    <com.notionalclues.errata.FabView
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_red_light"
        android:paddingTop="3dp"
        android:src="@drawable/ic_min"
        fabview:fab_attachAt="bottom_right"
        fabview:fab_attachTo="@id/fab_target"
        fabview:fab_attachType="inside"
        fabview:fab_padding="16dp"
        fabview:fab_revealAfterMs="300"
        fabview:fab_size="normal" />

</FrameLayout>

Solution

  • You have to change your width/height of your imageview:

    <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="fill_parent"             <--- full width
                    android:layout_height="match_parent"           <--- full height
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY" />         <--- will scale to full width/height
                                                              because you said you wanted that