Подогнать imageview к размеру прокрутки - PullRequest
0 голосов
/ 15 июля 2011

У меня есть HorizontalScrollView с 2 изображениями.HorizontalScrollView встроен в ScrollView.Мне бы хотелось, чтобы, если картинка была слишком большой (ширины и / или высоты), чтобы уместиться, она будет обрезана до размера ScrollView (не размера экрана).Если он меньше, без изменений.

Мой 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>

(Извините за мой плохой английский)

Ответы [ 3 ]

1 голос
/ 07 августа 2014

Пожалуйста, добавьте fadingEdge и fillViewport для scrollview и 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" >
1 голос
/ 15 июля 2011

Не могли бы вы сообщить нам, хотите ли вы обрезать изображение или масштабировать его?

Если вы хотите просто масштабировать большое изображение и привести его в соответствие, установите

android:cropToPadding="false" 

Подробнее об ImageView здесь

0 голосов
/ 09 июня 2019

Используйте это:

<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>
...