2015-05-04 169 views
0

我在ScrollView中有一个ImageView。 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匹配滚动型的总宽度和还保持宽高比?

不应该按照文档“fitCenter”自动匹配边缘吗?

ImageView.ScaleType。 FIT_CENTER

计算一个比例,将保持原来的SRC的纵横比,但 还将确保完全的src适合内部DST。至少有一个轴 (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做的工作。谢谢。 –