【问题标题】:how to remove empty spaces of imageview without cropping them如何删除imageview的空白而不裁剪它们
【发布时间】:2017-05-04 14:54:34
【问题描述】:

我正在尝试将ImageView 添加到我的CardView 但我不知道如何 在ImageView 内设置具有全宽的图像 (match_parent) 和wrap_content 高度!默认情况下会有 是 Imageview 中的一些空间(底部和顶部,取决于宽度和 图片的高度)如下所示:

有什么方法可以在不裁剪图像的情况下删除这些空白空间?

这是我的布局:

<?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>

【问题讨论】:

    标签: java android xml imageview instagram


    【解决方案1】:

    好的,问题解决了。
    一个非常简单的代码:

    android:adjustViewBounds="true"
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • scaletype 会裁剪图像,我自己找到了解决方案:您可以使用android:adjustViewBounds="true",图像将像 instagram 图像一样缩放
      猜你喜欢
      • 2023-01-12
      • 2021-12-25
      • 2014-01-21
      • 2011-05-01
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 2016-06-06
      • 1970-01-01
      相关资源
      最近更新 更多