Reputation: 75
I have a problem that when i add ImageView in ScrollView it shows empty space on top and bottom both side i want to show image on activity on full screen with width of fill screen and if image is long enough then screen then image will be scrollable. this code some how solve the issue but also showing empty area on top and bottom of the image.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context="com.alicon.digi.book.ScreenSlideActivity" >
<ImageView
android:id="@+id/bookImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/page_of_book"
android:src="@drawable/book_title" />
</ScrollView>
Upvotes: 0
Views: 1014
Reputation: 9700
add android:scaleType="fitXY"
attribute to the ImageView
XML and change android:layout_height
and android:layout_width
attributes' value from wrap_content
to fill_parent
. Use LinearLAyout
instead of ScrollView
as follows...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.alicon.digi.book.ScreenSlideActivity" >
<ImageView
android:id="@+id/bookImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:contentDescription="@string/page_of_book"
android:src="@drawable/book_title" />
</LinearLayout>
Upvotes: 0
Reputation: 6792
Please try this and pay attention to fillViewport property of ScrollView.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
**android:fillViewport="true"** //this is imp, see the link for a very good explanation
tools:context="com.alicon.digi.book.ScreenSlideActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bookImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:contentDescription="@string/page_of_book"
android:src="@drawable/book_title" />
</LinearLayout>
</ScrollView>
Upvotes: 1