Reputation: 3874
I have an HorizontalScrollView with 2 Imageview. The HorizontalScrollView is embedded in a ScrollView. I would like that if the picture is too big (width and/or height) to fit, it will be cropped to the size of the ScrollView (not the screen size). If it is smaller, no change.
My xml :
<ScrollView android:id="@+id/scrollView"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="@id/headerappview"
android:layout_above="@id/bottomBar"
android:background="@color/white">
<HorizontalScrollView android:layout_height="wrap_content"
android:layout_below="@+id/txtAdditionalContent"
android:id="@+id/hscrollview"
android:paddingBottom="22px"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content">
<LinearLayout android:layout_height="wrap_content"
android:gravity="center_vertical" android:layout_width="wrap_content">
<ImageView android:id="@+id/img2" android:src="@drawable/icon"
android:paddingRight="25px"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageView>
<ImageView android:id="@+id/img3" android:src="@drawable/icon"
android:cropToPadding="true"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</ImageView>
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
(Sorry for my poor english)
Upvotes: 0
Views: 4428
Reputation: 533
Use this:
<ImageView android:id="@+id/img3" android:src="@drawable/icon"
android:scaleType="centercrop"
android:adjustViewBounds="true"
android:layout_height="match_parent"
android:layout_width="wrap_content">
</ImageView>
Upvotes: 0
Reputation: 4904
Please add fadingEdge and fillViewport to scrollview and HorizontalScrollView
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:fadingEdge="none"
android:background="@drawable/bg_app" >
Upvotes: 1
Reputation: 576
Can you please let us know whether you would like to crop the image or scale the image ?
If you wish just to scale the large image and make it fit then set,
android:cropToPadding="false"
More about ImageView is here
Upvotes: 1