2

The problem is that i want to show a card view like custom view inside a list view. the view is showing fine in emulator but its not showing the same in emulator.

Here is the link to the image in which both preview can be seen simultaneously.

Code for list view :

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="10.0sp"
android:clipToPadding="false"
tools:listitem="@layout/listlayout">
</ListView>

Code for custom view:

<?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"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:elevation="10dp">


    <ImageView
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:id="@+id/productImage"
        android:layout_gravity="center" />



        <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_marginLeft="5dp"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/product_title"
            android:id="@+id/title"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="shortDescription"
            android:textSize="@dimen/abc_text_size_body_1_material"
            android:id="@+id/shortDescription" />
    </LinearLayout>

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="price"
            android:id="@+id/price"
            android:textAlignment="center"
            android:gravity="center"
            android:singleLine="true"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="newPrice"
            android:singleLine="true"
            android:id="@+id/newPrice"
            android:autoText="false"
            android:gravity="center" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:text="Buy"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:id="@+id/buy"
            android:gravity="center"
            android:layout_gravity="center" />
    </LinearLayout>
</LinearLayout>
samar abbas
  • 21
  • 1
  • 5

2 Answers2

5

You need to add one more parent layout on LinerLayout. There add property android:clipToPadding="false". For more read this reply Android "elevation" not showing a shadow

Community
  • 1
  • 1
Max
  • 5,493
  • 4
  • 26
  • 42
0

in XML of CardView try this:

app:cardUseCompatPadding="true" 
Androider
  • 3,691
  • 2
  • 11
  • 23
  • I have not used the card view its a list view in which i want to have a custom view . – samar abbas Sep 19 '15 at 18:45
  • On Lollipop it works setting elevation. For pre-Lollipop, you need to implement shadows by yourself. Which API version your Emulator is running ? – Sanjeev Sep 19 '15 at 19:29
  • i have been trying to run the app on api 21 and 22 ie 4.4.4 and 5.1 but no luck on any of the mentioned – samar abbas Sep 20 '15 at 16:11
  • use any view with the gradient in xml of your listview item to show something like shadow. – Androider Oct 08 '15 at 10:49