mercredi 28 juin 2017

how to set random background for cardview in android?

i currently have a android recyclerview and a listitem for it. in the listitem is a cardview for my views. i want to have random backgrounds for each card list this one : http://ift.tt/2soQGIn
my cards now have a solid background and i search every where and used any code but couldn't find a example for view like example.

please help me guys. thx !!!

my list item :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
    xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:id="@+id/card_view_lead"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    app:cardCornerRadius="10dp"
    app:cardPreventCornerOverlap="false">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/style_lead"
        android:padding="7dp">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@android:color/transparent"
            android:contentDescription="@string/option"
            android:src="@drawable/ic_option"
            android:tint="@android:color/white" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/large_margin"
            android:orientation="vertical">

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

                <com.makeramen.roundedimageview.RoundedImageView
                    android:id="@+id/lead_img"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:contentDescription="@string/test_pic"
                    app:riv_border_color="@color/colorPrimary"
                    app:riv_border_width="0.1dp"
                    app:riv_corner_radius="100dp"
                    tools:src="@drawable/pic_1" />

                <TextView
                    android:id="@+id/lead_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:layout_marginLeft="@dimen/standard_margin"
                    android:layout_toRightOf="@id/lead_img"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/large_font_size"
                    tools:text="@string/test_name" />

            </RelativeLayout>

            <TextView
                android:id="@+id/lead_city"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/standard_margin"
                android:layout_marginTop="16dp"
                android:textColor="@android:color/white"
                android:textSize="@dimen/large_font_size"
                tools:text="@string/test_city" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/standard_margin">

                <TextView
                    android:id="@+id/lead_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/large_font_size"
                    tools:text="30$" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/large_margin"
                    android:layout_marginTop="16dp"
                    android:layout_toRightOf="@id/lead_price"
                    android:text="@string/per_hour"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/large_font_size" />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="20dp"
                android:layout_marginTop="16dp">

                <TextView
                    android:id="@+id/with"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/standard_margin"
                    android:text="@string/with"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/large_font_size" />

                <TextView
                    android:id="@+id/lead_vehicle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="6dp"
                    android:layout_toRightOf="@id/with"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/large_font_size"
                    tools:text="@string/car" />

                <ImageView
                    android:id="@+id/lead_vehicle_img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_toRightOf="@id/lead_vehicle"
                    android:contentDescription="@string/car_img"
                    tools:src="@drawable/ic_car" />
            </RelativeLayout>
        </LinearLayout>
    </RelativeLayout>

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




Aucun commentaire:

Enregistrer un commentaire