How to add colored border on cardview?

前端 未结 7 1682
遥遥无期
遥遥无期 2020-12-13 05:56

I am new to Android and this is my first question here.

I am trying to add a colored vertical border at the beginning of the cardview. How can I achieve it on xml ?

相关标签:
7条回答
  • 2020-12-13 06:42

    I solved this by putting two CardViews in a RelativeLayout. One with background of the border color and the other one with the image. (or whatever you wish to use)

    Note the margin added to top and start for the second CardView. In my case I decided to use a 2dp thick border.

                <android.support.v7.widget.CardView
                android:id="@+id/user_thumb_rounded_background"
                android:layout_width="36dp"
                android:layout_height="36dp"
                app:cardCornerRadius="18dp"
                android:layout_marginEnd="6dp">
    
                <ImageView
                    android:id="@+id/user_thumb_background"
                    android:background="@color/colorPrimaryDark"
                    android:layout_width="36dp"
                    android:layout_height="36dp" />
    
            </android.support.v7.widget.CardView>
    
            <android.support.v7.widget.CardView
                android:id="@+id/user_thumb_rounded"
                android:layout_width="32dp"
                android:layout_height="32dp"
                app:cardCornerRadius="16dp"
                android:layout_marginTop="2dp"
                android:layout_marginStart="2dp"
                android:layout_marginEnd="6dp">
    
            <ImageView
                android:id="@+id/user_thumb"
                android:src="@drawable/default_profile"
                android:layout_width="32dp"
                android:layout_height="32dp" />
    
            </android.support.v7.widget.CardView>
    
    0 讨论(0)
提交回复
热议问题