当前位置: 首页 > 知识库问答 >
问题:

CardView不缩放图像

壤驷鸿
2023-03-14

以下是CardView的XML代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="5dp"
    app:cardElevation="0dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true"
    app:contentPadding="0dp"
    card_view:cardBackgroundColor="@android:color/transparent"
    app:contentPaddingBottom="0dp"
    app:contentPaddingLeft="7dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">



        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="2dp"
            android:adjustViewBounds="true"/>




        </LinearLayout>

</androidx.cardview.widget.CardView>

我尝试对ImageView(和LinearLayout)的属性使用wrap_content,并尝试包含属性android: caleType="fitXY",但它没有帮助,似乎没有任何效果。

谁能帮我一下吗?我非常感谢您的每一句评论,也非常感谢您的帮助。

共有1个答案

侯兴为
2023-03-14

您需要为任何视图提供固定高度,如

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="120dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="5dp"
    app:cardElevation="0dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true"
    app:contentPadding="0dp"
    card_view:cardBackgroundColor="@android:color/transparent"
    app:contentPaddingBottom="0dp"
    app:contentPaddingLeft="7dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">



        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="2dp"
            android:adjustViewBounds="true"/>




        </LinearLayout>

</androidx.cardview.widget.CardView>
 类似资料:
  • 图表缩放指的是局部放大或缩小图表,可以更方便的查看图表数据。 Highcharts支持两种方式缩放,缩放(zoom)和平移(panning), 并且是完美支持移动端手势操作的 。 一、缩放(zoom) 只需要简单设置 zoomType 即可实现图表缩放,例如: $("#container").highcharts({ chart: { zoomType: 'x' } // ..

  • 我想在我的Android应用程序中增加位图的大小。 基本上,我想创建一个新的位图,其宽度与原始位图相同,但高度更大。(新)额外像素的背景可以是黑色、白色或透明。 我该怎么做?

  •        地图缩放调整方法:设置-实验室(可参考10.1)-测地图缩放        将缩放比例调整好后,重新启动外业精灵即可展示修改后的缩放效果。

  • 问题内容: 改变的大小的图像在GWT部件改变所述图像元素的大小,但不重新调整屏幕上的图像。因此,以下操作将无效: 这是因为GWT 通过使用CSS 将HTML 元素的设置为图像来实现其Image小部件。 如何获得要调整尺寸的实际图像? 问题答案: 我看到了此博客条目,该条目通过使用GWT DataResource而不是ImageResource解决了问题。事实证明,如果您按以下方式使用它,则Imag

  • 主要内容:创建缩略图,批量修改图片尺寸在图像处理过程中经常会遇到缩小或放大图像的情况,Image 类提供的 resize() 方法能够实现任意缩小和放大图像。 resize() 函数的语法格式如下: 参数说明: size:元组参数 (width,height),图片缩放后的尺寸; resample:可选参数,指图像重采样滤波器,与 thumbnail() 的 resample 参数类似,默认为 Image.BICUBIC; box:对