0

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://i.stack.imgur.com/9kZi6.jpg

propoLis
  • 1,229
  • 1
  • 14
  • 48

2 Answers2

2

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

enter image description here

Faiz Mir
  • 599
  • 5
  • 16
  • Doesnt work and the image you are using is not taking complete width of cardview use an image which takes complete width of cardview then see it wont take corner radius of cardview @Faiz Mir –  May 16 '18 at 09:24
  • send me a image which you are using faizmir53@gmail.com – Faiz Mir May 16 '18 at 09:25
0

Since android:hardwareAccelerated="true" was added in the manifest, I removed it and it worked

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"            //<--
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.TestLib">
    ...
</application>
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 16 '22 at 17:58