2016-07-07 239 views
0

所以我遇到了一個問題,縮放我的圖像,以適合我的主屏幕。縮放我的項目圖像,以適當地適應屏幕

下面是一些截圖。

身高問題

The height is not as big as it should be

寬度問題

Here the height is right but not the width

我想要實現這樣的

enter image description here

XML商品代碼

<?xml version="1.0" encoding="utf-8"?> 
<com.inthessaloniki.cityguide.view.SelectorRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/fragment_poi_list_item" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:listSelector="@drawable/selector_clickable_item_bg_inverse"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MainActivity"> 

     <ImageView 
      android:id="@+id/fragment_poi_list_item_image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scaleType="fitXY"/> 

    </RelativeLayout> 

</com.inthessaloniki.cityguide.view.SelectorRelativeLayout> 

我希望圖像匹配父寬度,但是會相應地縮放它們的高度。

回答

0

scaleType =「fitXY」強制圖像固定到屏幕並且不保持寬高比。

試試這個

<ImageView 
     android:id="@+id/fragment_poi_list_item_image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="centerCrop" 
     android:adjustViewBounds="true"/> 
0

在我發現了一個解決方案結束。 這是爲了防止有人遇到同樣的問題。

我用scaleY和填充來適應圖像。

<ImageView 
    android:id="@+id/fragment_poi_list_item_image" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="7dp" 
    android:paddingBottom="7dp" 
    android:scaleType="fitXY" 
    android:scaleY="1.25"/>