image in cardview with top radius not showing corner radius

点点圈 提交于 2019-12-13 03:46:58

问题


I have recyclerView which insides cardView that has ImageView and it takes 70% height of its. So I have given corner radius to cardView. The bottom of cardView radius is shown but the problem is the top part which is covered by image is not taking the corner radius of cardView.

I tried these questions : question , question. But still the problem remains the same.

xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/_200sdp"
    android:layout_marginRight="@dimen/_15sdp"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="15dp"
    card_view:cardCornerRadius="@dimen/_20sdp"
    card_view:cardBackgroundColor="@color/White"
    android:layout_marginBottom="@dimen/_10sdp">

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

        <ImageView
            android:id="@+id/party_image"
            android:layout_width="@dimen/_160sdp"
            android:layout_height="@dimen/_140sdp"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/party_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            android:text="John Doe"
            android:textColor="@color/colorPrimary"
            android:gravity="center"
            android:paddingBottom="8dp"
            android:paddingTop="8dp"
            />

    </LinearLayout>

</android.support.v7.widget.CardView>

My output image: https://imgur.com/a/FequXmj


回答1:


Try this..

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"

    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_gravity="center"

    android:layout_margin="8dp"
    android:background="@drawable/shape"

    android:elevation="4dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:elevation="4dp"
        app:cardCornerRadius="8dp">

        <ImageView
            android:id="@+id/thumbnaill"
            android:layout_width="160dp"
            android:layout_height="140dp"
            android:layout_gravity="left"
            android:background="@drawable/sa"
            android:scaleType="fitXY"
            />
    </android.support.v7.widget.CardView>
</FrameLayout>

And in you Drawable make a xml shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">
    <!-- you can use any color you want I used here gray color-->
    <solid android:color="#ffffff"/>
    <corners android:radius="8dp"/>
    <!--<stroke android:width="0.5dp" android:color="@color/darker_gray"/>-->
</shape>

It will look like this...Result



来源:https://stackoverflow.com/questions/50364978/image-in-cardview-with-top-radius-not-showing-corner-radius

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!