Vinay Nagaraj Vinay Nagaraj - 15 days ago 6
Android Question

Android won't respect card_view attributes

I have the following in an xml file called item_school.xml, and I'm inflating it to populate my recyclerview. The recycler view respects the android:layout* attributes and changes the layout spacing between cards when I change these attributes, but when I add any card_view attributes the view does not change.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"

card_view:cardCornerRadius="50dp"
card_view:cardElevation="50dp">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:paddingTop="@dimen/activity_vertical_margin">

<TextView
android:id="@+id/item_school_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="sans-serif-medium"
android:textAlignment="center"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp" />

<TextView
android:id="@+id/item_school_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:textColor="?android:attr/textColorTertiary"
android:textSize="12sp" />

</LinearLayout>

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


I bumped up the radius and elevation to 50dp, and even tried changing the background to black but the view still looks the same (default background, corners and shadow). It seems like the default values are overriding the ones I have in the xml. What do I need to do?

EDIT: Target SDK:23, Min SDK:15

Answer

I think you're using wrong namespace for the cardview. Try to use :

xmlns:card_view="http://schemas.android.com/apk/res-auto"

instead of

xmlns:card_view="http://schemas.android.com/tools"