Skip to content

Instantly share code, notes, and snippets.

@zawawimanja
Created March 22, 2020 13:51
Show Gist options
  • Save zawawimanja/45f756d548fb9e1bdfd913306e49bc57 to your computer and use it in GitHub Desktop.
Save zawawimanja/45f756d548fb9e1bdfd913306e49bc57 to your computer and use it in GitHub Desktop.
CardView Relative Layout
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="@dimen/card_height"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/md_keylines"
android:layout_marginLeft="@dimen/md_keylines"
android:layout_marginRight="@dimen/md_keylines"
android:foreground="?attr/selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/card_image"
android:layout_width="match_parent"
android:layout_height="@dimen/card_image_height"
android:scaleType="centerCrop"
tools:src="@drawable/a" />
<TextView
android:id="@+id/card_title"
android:layout_width="match_parent"
android:layout_height="@dimen/card_title_height"
android:layout_alignBottom="@+id/card_image"
android:layout_marginLeft="@dimen/md_keylines"
tools:text="@string/item_title"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@color/white" />
<TextView
android:id="@+id/card_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/card_image"
android:layout_marginLeft="@dimen/md_keylines"
android:layout_marginTop="@dimen/md_keylines"
android:layout_marginBottom="@dimen/md_keylines"
android:layout_marginRight="@dimen/md_keylines"
tools:text="@string/item_desc"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@color/dark_grey"
android:textSize="@dimen/article_subheading" />
<Button
android:id="@+id/action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/card_text"
style="?android:attr/borderlessButtonStyle"
android:textColor="?attr/colorPrimary"
android:text="Action" />
<ImageButton
android:id="@+id/share_button"
android:layout_width="@dimen/cards_button_width"
android:layout_height="@dimen/cards_button_height"
android:layout_marginRight="@dimen/md_keylines"
app:srcCompat="@drawable/ic_share"
android:layout_below="@+id/card_text"
android:layout_alignParentRight="true"
style="?android:attr/borderlessButtonStyle"
android:tint="@color/button_grey" />
<ImageButton
android:id="@+id/favorite_button"
android:layout_width="@dimen/cards_button_width"
android:layout_height="@dimen/cards_button_height"
android:layout_marginRight="@dimen/md_keylines"
app:srcCompat="@drawable/ic_favorite"
android:layout_below="@+id/card_text"
android:layout_toLeftOf="@id/share_button"
style="?android:attr/borderlessButtonStyle"
android:tint="@color/button_grey" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment