3

Hi i'm developing an app where i'm using imageview inside cardview but my problem is that imageview somehow is not taking the corner radius applied to cardview Please see the image below enter image description here I tried doing different things but dont understand where the problem is please if anyone can guide me my xml

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_margin="4dp"
    android:id="@+id/cardview2"
    app:cardCornerRadius="25dp"
    card_view:cardPreventCornerOverlap="false"
    >

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

        <ImageView
            android:layout_width="88dp"
            android:layout_height="88dp"
            android:id="@+id/imageView"
            android:scaleX="1.2"
            android:scaleType="fitXY"
            android:scaleY="1.2"
            android:src="@drawable/club1"
            android:background="@drawable/corner_radius"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:id="@+id/nameTextView"
            android:layout_marginLeft="4dp"
            android:layout_marginStart="4dp"
            android:layout_marginTop="16dp"
            android:maxLines="2"
            android:text="Item"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:id="@+id/ratingTextView"
            android:layout_marginStart="4dp"
            android:drawableEnd="@color/White"
            android:drawableRight="@color/White"
            android:drawablePadding="2dp"
            android:text="4,5"
            android:gravity="center"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1"
            android:textSize="12sp"/>



    </LinearLayout>

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

5 Answers5

3

See here is the Image. Remeber Don't make CardView as Main Layout.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="1dp"
    android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    app:cardUseCompatPadding="true"
    android:elevation="0dp"
    app:cardCornerRadius="5dp"
    android:layout_height="wrap_content">

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


        <ImageView
            android:id="@+id/iv_suvichar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/placeholder" />

        <TextView
            android:id="@+id/tv_suvichar_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Title"
            android:padding="5dp"
            android:textColor="@color/black"
            android:textSize="@dimen/normal_text_size" />

    </LinearLayout>

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

Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105
  • Hi thanks for you response but i ende up using custom imageview as @Nilesh suggested –  Apr 30 '18 at 07:52
2

Try Replace your Linear Layout with Relative Layout. After that set gravity of your last textview (center_horizontal).

4b0
  • 21,981
  • 30
  • 95
  • 142
Satyam
  • 41
  • 1
  • 5
1

You can use the RoundedImageView :

Put this in the build.gradle

compile 'com.makeramen:roundedimageview:2.3.0'

And to use it:

<com.makeramen.roundedimageview.RoundedImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@android:color/transparent"
    android:scaleType="centerCrop"
    app:riv_corner_radius="5dp"/>
Khalid Taha
  • 3,183
  • 5
  • 27
  • 43
0

Just use this code in xml and see result after RUN the code:

<android.support.v7.widget.CardView
    android:layout_marginTop="100dp"
    android:layout_gravity="center_horizontal"
    app:cardCornerRadius="20dp"
    android:id="@+id/cv"
    android:clipChildren="true"
    android:layout_width="100dp"
    android:layout_height="wrap_content">

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

    <ImageView
        android:scaleType="centerCrop"
        android:src="@drawable/recipe"
        android:layout_width="match_parent"
        android:layout_height="100dp" />

        <TextView
            android:layout_margin="8dp"
            android:text="ITEM"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_marginLeft="8dp"
            android:layout_marginBottom="8dp"
            android:text="34"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
</android.support.v7.widget.CardView>
Deven
  • 3,078
  • 1
  • 32
  • 34
  • hi Deven can you help me with this https://stackoverflow.com/questions/49939514/trying-to-implement-viewpager-with-cardstack-swipe-animation –  Apr 30 '18 at 07:59
-1

please find Try this way :

  <?xml version="1.0" encoding="utf-8"?>
  <android.support.v7.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:cardview="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:padding="@dimen/_5sdp"
  android:layout_marginTop="@dimen/_5sdp"
  android:layout_marginLeft="@dimen/_5sdp"
  android:layout_marginRight="@dimen/_5sdp"
  android:layout_marginBottom="5dp"
  cardview:cardCornerRadius="@dimen/_3sdp"
  cardview:cardElevation="@dimen/_3sdp"
  cardview:cardUseCompatPadding="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_180sdp"
        android:layout_alignParentTop="true"
        android:scaleType="centerCrop"
        android:src="@drawable/placeholder"/>



    <RelativeLayout
        android:padding="@dimen/_5sdp"
        android:id="@+id/rlMiddle"
        android:layout_below="@+id/thumbnail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/txtPrescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_10sdp"
            android:maxLines="3"
            android:paddingTop="8dp"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            android:textSize="@dimen/_16sdp"
            android:text="Demo"
            android:textStyle="bold"
           />
      </RelativeLayout>
    </RelativeLayout>
 </android.support.v7.widget.CardView>
jeet parmar
  • 868
  • 8
  • 19