【发布时间】:2020-01-29 21:20:13
【问题描述】:
我正在尝试使用 Glide 在带有圆角的卡片视图中显示图像视图,但是图像将卡片视图的角扩展为方形,而相同的代码在卡片视图 v7 支持库中运行良好,但在 androidx 中却没有。知道这个问题已经有很多答案,但没有一个对我有用。
我正在使用回收器视图来显示来自服务器的所有项目,这是托管片段代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dashboard_background"
android:id="@+id/mparent"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/category_choose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="190dp"
android:layout_height="48dp"
android:background="@drawable/search_backround"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<ImageView
android:id="@+id/imageView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/buy_medicine" />
<ImageView
android:id="@+id/category_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
app:srcCompat="@drawable/bg_spinner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/category_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"
android:text="@string/category"
android:maxLines="1"
android:textColor="@color/Nero"
android:fontFamily="@font/montserrat_black"
android:textSize="@dimen/_text_size_12sp"
android:ellipsize="end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/category_spinner"
app:layout_constraintStart_toEndOf="@+id/imageView16"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/shimmer_Effect_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/category_choose">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<include
layout="@layout/category_list_layout"/>
<include
layout="@layout/category_list_layout"/>
<include
layout="@layout/category_list_layout"/>
</LinearLayout>
<LinearLayout
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<include
layout="@layout/category_list_layout"/>
<include
layout="@layout/category_list_layout"/>
<include
layout="@layout/category_list_layout"/>
</LinearLayout>
</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_category_lists"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/shimmer_Effect_category"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是 CardView 的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="@dimen/_5sdp"
android:id="@+id/category_list"
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:scaleType="fitXY"
app:cardCornerRadius="@dimen/_15sdp"
app:cardPreventCornerOverlap="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/categoryImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:scaleType="fitXY"
/>
<TextView
android:id="@+id/categoryName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:gravity="center"
android:text="Foods"
android:textColor="@color/black"
android:textSize="@dimen/_text_size_12sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
那么我在这里做错了什么?请推荐!
【问题讨论】:
-
你可以试试 MaterialComponents 库中新的 ShapeableImageView。检查this answer。
-
@GabrieleMariotti 当然,Gabriele 我也会试试这个,谢谢你的信息。
标签: android android-imageview android-cardview androidx