2015-05-04 3 views
0

У меня есть ImageView внутри ScrollView. Ширина и высота ImageView и match_parent и wrap_content. Но ImageView имеет небольшое дополнение слева и справа от него. Изображение загружается с сервера и отображается в ImageView.ImageView - Нежелательное дополнение слева и справа

Вот мой XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/com.xx.xxx" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar_without_spinner" /> 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="none" > 

     <LinearLayout 
      android:id="@+id/ll_select_activity" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/green" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:id="@+id/ll_feature" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <LinearLayout 
        android:id="@+id/text_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:orientation="vertical" 
        android:paddingBottom="10dp" 
        android:paddingTop="10dp" 
        android:visibility="gone" > 

        <TextView 
         android:id="@+id/item_features_title" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center" 
         android:text="@string/empty" 
         android:textAppearance="?android:attr/textAppearanceLarge" /> 

        <TextView 
         android:id="@+id/item_features_description" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center" 
         android:text="@string/empty" 
         android:textAppearance="?android:attr/textAppearanceMedium" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" > 
        <!-- ImageView with the problem --> 
        <ImageView 
         android:id="@+id/item_features_imageview_icon" 
         android:layout_width="0dip" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:adjustViewBounds="true" 
         android:padding="0dp" 
         android:contentDescription="@string/item_features_icon" 
         android:cropToPadding="false" 
         android:scaleType="fitCenter" /> 
       </LinearLayout> 
      </LinearLayout> 

      .... 
      .... 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

Вы можете найти скриншоты ниже:

enter image description here

enter image description here

Как я сделать ImageView соответствовать общей ширине Scrollview и также поддерживать соотношение сторон?

Не должен ли «fitCenter» автоматически соответствовать краям, согласно документации?

ImageView.ScaleType. FIT_CENTER

Вычислить масштаб, который будет поддерживать исходное соотношение сторон SRC, но также гарантирует, что SRC подходит полностью внутри ДСТ. По крайней мере одна ось (X или Y) будет точно соответствовать. Результат центрирован внутри dst.

+0

попробуйте изменить 'andro id: scaleType = "fitCenter" 'to android: scaleType =" fitXY "' –

+0

ok .. Но, будет ли fitXY поддерживать «соотношение сторон» загруженного изображения? Я хочу поддерживать соотношение сторон, потому что я не хочу, чтобы изображение растягивалось или сжималось –

ответ

0

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

android:scaleType="fitX" 

Это расширит ваше изображение в горизонтальном удалении Лишние отступы

Вы можете также использовать

android:scaleType="fitXY" 

Она будет расширяться как в вертикальном, так и горизонтальный

+0

Ну, хотя я хотел пойти только с fitCenter концептуально, fitXY выполнил эту работу. Благодарю. –

Смежные вопросы