Abdul Salam
Abdul Salam

Reputation: 11

Can't add elevation and radius to my cardview

This is my UI Design: UI Design

And this is my xml code:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="40dp"
        android:layout_marginTop="32dp">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnOrderPreserved="false"
            android:alignmentMode="alignMargins"
            android:rowCount="2"
            android:columnCount="2"
            >

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_columnWeight="1"
                android:layout_rowWeight="1"
                android:layout_margin="12dp"
                app:cardCornerRadius="20dp" <--- :"(
                app:cardElevation="20dp" <--- :"(
                >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:clipToPadding="false"
                    android:padding="16dp"
                    android:orientation="vertical"
                    android:background="@drawable/rounded_square">

                    <ImageView
                        android:layout_width="80dp"
                        android:layout_height="80dp"
                        android:layout_gravity="center"
                        android:src="@drawable/dashPlaceholder"
                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:textSize="8pt"
                        android:text="@string/findBengkel"/>
                </LinearLayout>

            </androidx.cardview.widget.CardView>

            ...


        </GridLayout>


    </LinearLayout>

and this is the result: result

Upvotes: 0

Views: 781

Answers (2)

Emon Hossain Munna
Emon Hossain Munna

Reputation: 755

<androidx.cardview.widget.CardView
                    android:id="@+id/card_view_DailyTicket"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:backgroundTint="@color/grey"
                    app:cardCornerRadius="10dp"
                    app:cardElevation="0dp">

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

                        <ImageView
                            android:layout_width="80dp"
                            android:layout_height="80dp"
                            android:src="@drawable/ic_baseline_directions_car_24" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Hourly Tickets"
                            android:textColor="@color/purple_700"
                            android:textStyle="bold" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

Try this. from my current project. its piece of cake. runs well. hope that will help

Upvotes: 1

Emon Hossain Munna
Emon Hossain Munna

Reputation: 755

app:cardCornerRadius="20dp"
app:cardElevation="0dp"

and also use backgroundTint with any color to confirm if its working or not. i edited your Card and it Worked!

and most importantly manage your grid layout width and height nicely either you would get difficulties.

Upvotes: 0

Related Questions