java - 如何删除 ImageView 的空白区域而不裁剪它们

标签 java android xml imageview instagram

I'm trying to add a ImageView to my CardView but i don't know how to set image inside of ImageView that has a Full Width (match_parent) and a wrap_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 :

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

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/

相关文章:

java - 将 Button 更改为 JButton 无法修复它(((

java - 无法下载在 Google Play 上发布的测试版 APK

android - 在外部存储API 23上创建新目录

Java MySql 准备语句

android - 仅发布适用于 Android v4.4.3+ 的应用程序?

android - 如果应用程序已经在运行,它会启动吗?

java - 从 mysql DB 检索数据后如何创建 XML 文件?

android - 我想在 Android Studio 中使用按钮样式 "Widget.Button.Transparent"

xml - ENAMETOOLONG 请求 xml 文档

java - 如何编写使用 * 打印大写字母 F 的嵌套循环