简体   繁体   English

ImageView 隐藏父对象的圆角

[英]ImageView hides the round corners of the parent

I have a CardView as parent and inside the CardView I have a ConstraintLayout and defined a border for the ConstraintLayout.我有一个 CardView 作为父级,在 CardView 内部我有一个 ConstraintLayout 并为 ConstraintLayout 定义了一个边框。 But the problem is that the border disappears when it reaches the imageView I put inside ConstraintLayout and it can't be seen anymore但是问题是当它到达我放在 ConstraintLayout 中的 imageView 时边框消失了,并且再也看不到了

https://imgur.com/dELnfoB https://imgur.com/dELnfoBtwo muppets

Now to fix this problem, I set the top and bottom and right margins as 1dp for imageView because my border is 1dp wide, but still the problem is that the corner angle has a problem and gets narrow and is not displayed clearly现在为了解决这个问题,我把imageView的上下边距和右边距都设置为1dp,因为我的边框是1dp宽的,但是问题仍然是角角有问题,变窄了,显示不清晰

two muppets

By the way, I don't want to use cardElevation顺便说一句,我不想​​使用cardElevation

item code :项目代码 :

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cv_item_parent"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusable="true"
android:layoutDirection="ltr"
app:cardCornerRadius="4dp"
app:cardElevation="0dp">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/pc_corners_parent_gray_stroke">

    <ImageView
        android:id="@+id/iv_item_avatar"
        android:layout_width="130dp"
        android:layout_height="0dp"
        android:layout_marginTop="1dp"
        android:layout_marginEnd="1dp"
        android:layout_marginBottom="1dp"
        android:scaleType="fitXY"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/wqe" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="1dp"
        android:layout_marginBottom="1dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/iv_item_avatar"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <TextView
            android:id="@+id/tv_item_rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="4.0 ★"
            android:textColor="@color/colorTextPrimary"
            android:textDirection="ltr"
            android:textSize="@dimen/text_tiny_other"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

corners code:角码:

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="@color/colorWhite"/>
    <corners android:radius="4dp"/>
    <stroke android:width="1dp" android:color="@color/colorCardViewsBackgroundSet" android:dashWidth="1dp"/>

</shape>

You can put the ImageView inside a CardView and it should keep the corners round.您可以将 ImageView 放在 CardView 中,它应该保持圆角。 I am not sure if it's the best way to go about it but it works.我不确定这是否是最好的方法,但它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM