fluffow
fluffow

Reputation: 35

android ImageView adjustViewBounds not working. Whitespace

I have this problem that when I run application I get undesired white space on top of and below my image views.

I have tried to use adjustViewBounds and different scale types, the thing is I want to keep my pictures, exactly as they are, but just remove the whitespace.

The Imageviews changes to a src picture in my java code where I download the pictures to the phones activity and then set the image to the downloaded bitmap.

Here is a picture of how it looks on my emulator, there is one full screen of whitespace until you get to the next imageView, by scrolling down on the ScrollView.

enter image description here

Here you can see my XML code. TouchImageView is just a zoomable type of imageView.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:fillViewport="true" >

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

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

        <TextView
            android:id="@+id/tVInformation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="TextView"
            android:visibility="gone" />

        <com.fluffow.csgosmokes.TouchImageView
            android:id="@+id/iVsmoke1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:scaleType="centerInside"
            android:src="@drawable/ic_launcher" />

        <com.fluffow.csgosmokes.TouchImageView
            android:id="@+id/iVsmoke2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:scaleType="centerInside"
            android:src="@drawable/ic_launcher" />

        <com.fluffow.csgosmokes.TouchImageView
            android:id="@+id/iVsmoke3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:scaleType="centerInside"
            android:src="@drawable/ic_launcher" />

        <com.fluffow.csgosmokes.TouchImageView
            android:id="@+id/iVsmoke4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:scaleType="centerInside"
            android:src="@drawable/ic_launcher"
            android:visibility="invisible" />
    </LinearLayout>
</RelativeLayout>

An interesting thing is the fact that each imageview got exactly one android simulator screen "whitespace" between each other, and that if I color one imageviews-background half of the whitespace will be that color, the next half is from the next imageview. It got the same amount of whitespace before and after the imageview.

Upvotes: 0

Views: 1180

Answers (4)

fluffow
fluffow

Reputation: 35

The problem was with the touchImageView. It created a whitespace which could not be removed.

Upvotes: 1

Lamorak
Lamorak

Reputation: 11137

Try to remove adjustViewBounds. This might produce whitespace on the sides if your bitmap has smaller width than the screen but it works great otherwise.

Upvotes: 0

Maher Malaeb
Maher Malaeb

Reputation: 341

Remove the android:scaleType="centerInside" from your TouchImageView and the white spaces between the consecutive TouchImageView should be removed.

Upvotes: 0

Nauman Afzaal
Nauman Afzaal

Reputation: 1046

You are using scale type centerInside and what it actually does is

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

Now your height is wrap_content so it will scale while maintaining the aspect ratio and once it hit either dimension it wont scale beyond that. If you want to remnove white space remove scaleType

Upvotes: 0

Related Questions