I'm trying to add a
ImageView
to myCardView
but i don't know how to set image inside ofImageView
that has a Full Width (match_parent
) and awrap_content
height ! By default there would be some spaces in Imageview (bottom and top parts, depend on width and height of image) as you see below :
any way to remove these empty spaces without cropping images ?
这是我的布局:
<?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>
最佳答案
好的,问题解决了。
非常简单的代码:
android:adjustViewBounds="true"
关于java - 如何删除 ImageView 的空白区域而不裁剪它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43786334/