android - 如何调整图像大小以正确适合卡片视图
问题描述
您好,我正在尝试将图像大小调整为卡片视图的大小,但有些图像适合,其中一些不希望所有图像都适合卡片视图
我已经使用了所有比例类型,但我发现最好的是中心裁剪,但使用后仍然有些图像不合适
这是XML代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp">
<com.google.android.material.card.MaterialCardView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:layout_marginStart="1dp"
android:layout_marginTop="11dp"
android:layout_marginEnd="1dp"
app:cardCornerRadius="13dp"
app:cardElevation="1dp"
app:cardMaxElevation="4dp">
<com.google.android.material.imageview.ShapeableImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="@string/todo"
android:scaleType="centerCrop"
app:shapeAppearanceOverlay="@style/RoundedCorner" />
</com.google.android.material.card.MaterialCardView>
</RelativeLayout>
解决方案
内卡视图使用:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/todo"
android:scaleType="centerCrop"
app:shapeAppearanceOverlay="@style/RoundedCorner" />
推荐阅读
- variables - Ansible:在 v2.3 中动态查找变量
- c - printf 什么返回 c 但出现错误
- google-cloud-platform - 无法在 GCP 中创建云函数
- apache2 - 为什么 phpldapadmin 在浏览器中显示代码?
- javascript - Javascript - 我需要相当于 jQuery 触发器点击 ID
- javascript - 我不想为使用 electron-packager 打包的 Electron 应用程序构建一个特定目录
- r - 使用逻辑或在 R 中的数据框中组合几个布尔变量
- task - Verilog:为局部变量连续分配输出的任务
- c++ - c++程序未正确打印二维矢量网格但已关闭
- excel - 如何运行具有特定变化和布局的 IW29 并将其结果复制到 excel?