2017-05-04 124 views
0

我尝试添加ImageViewCardView,但我不知道如何 设置的ImageView内图像具有全宽 (match_parent)和高度为wrap_content!默认情况下,将有 在ImageView的一些空间(底部和顶部的部分,取决于宽度和 高度图象的),你看下面:如何删除的ImageView的空白空间不裁剪他们

how does instagram fill it's images without cropping them?

另一个例子:

how does instagram fill it's images without cropping them?

任何方式删除这些空没有裁剪图像的空间?

这里是我的布局:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/cardview2" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_margin="5dp" 
android:clickable="true" 
android:focusable="true" 
android:foreground="?android:attr/selectableItemBackground" 
app:cardElevation="3dp"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <RelativeLayout 
     android:id="@+id/cardviewLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ryan_gosling" 
      /> 
    </LinearLayout> 

</RelativeLayout> 
</android.support.v7.widget.CardView> 

回答

0

确定的问题就解决了。
一个非常简单的代码:

android:adjustViewBounds="true" 
0

你可以尝试添加scaletype到ImageView的。这实际上会根据您给予的价值来缩放图像。 Here you can refer it.

+0

'scaletype'会裁剪图像,我自己找到了解决方法:您可以使用android:adjustViewBounds =“true”'图像将像instagram图像一样缩放 –