I want to create a layout with a CardView, which contains a header with an other background color, similar to what is shown in the current Google Now screen (See below).
The darker colored header (containing the text "iPhone 6") extends completely towards the edges and rounded corners of the CardView.
I tried to build a similar CardView with the support-v7 library (android.support.v7.widget.CardView).
Screenshot below.
In my case, the blue background color of the header however, does not fully extend towards the edges of my CardView. There is a small white border (the background color of the CardView) visible at the left, upper and right edges. This seems to be a consequence of the rounded corners of the CardView.
How can I get the background color of my header (a TextView), to extend completely towards the edges and rounded corners of my CardView?
This is the relevant part of my xml layout file:
<android.support.v7.widget.CardView
android:id="@+id/calendar_detail_time_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/calendar_detail_title_card"
android:layout_margin="6dp"
card_view:cardCornerRadius="3dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:background="@color/primaryColor"
android:padding="8dp"
android:textSize="@dimen/calendar_detail_large"
android:textStyle="bold"
android:id="@+id/header_when"
android:text="@string/header_when"
tools:text="When?"/>
<ImageButton
android:id="@+id/calendar_detail_add_to_calendar_button"
style="?android:borderlessButtonStyle"
android:layout_width="@dimen/calendar_detail_add_to_calendar_image"
android:layout_height="@dimen/calendar_detail_add_to_calendar_image"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_calendar_red" />
<TextView
android:id="@+id/calendar_detail_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header_when"
android:padding="8dp"
tools:text="Time" />
</RelativeLayout>
</android.support.v7.widget.CardView>
CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.
To efficiently reuse complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.
Add this code to your card in xml:
card_view:cardPreventCornerOverlap="false"
And now it will extend all the way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With