Created
August 4, 2017 06:47
-
-
Save n1lesh/2c1460379166bff9e21bcb123f95bd81 to your computer and use it in GitHub Desktop.
Android CardView Sample - XML and Java Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CardView cardView = (CardView) findViewById(R.id.cardView); | |
cardView.setUseCompatPadding(true); | |
cardView.setContentPadding(30, 30, 30, 0); | |
cardView.setPreventCornerOverlap(true); | |
cardView.setCardBackgroundColor(Color.WHITE); | |
cardView.setCardElevation(2.1f); | |
cardView.setRadius(0); | |
cardView.setMaxCardElevation(3f); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.v7.widget.CardView | |
android:layout_width="match_parent" | |
android:layout_height="250dp" | |
app:cardBackgroundColor="@android:color/white" | |
app:cardCornerRadius="0dp" | |
app:cardMaxElevation="1dp" | |
app:cardElevation="0.7dp" | |
app:contentPadding="10dp" | |
app:contentPaddingBottom="0dp" | |
app:cardPreventCornerOverlap="true" | |
app:cardUseCompatPadding="true" | |
android:id="@+id/cardView"> | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:layout_width="match_parent" | |
android:layout_height="180dp" | |
android:scaleType="centerCrop" | |
android:id="@+id/img" | |
android:src="@drawable/joshua_sortino" | |
android:contentDescription="CardImageViewDesc" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_below="@id/img" | |
android:layout_marginLeft="5dp" | |
android:layout_marginStart="5dp" | |
android:fontFamily="sans-serif" | |
android:gravity="center_vertical" | |
android:text="Joshua Sortino - Via Unsplash" | |
android:textSize="18sp" /> | |
<ImageButton | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_alignParentEnd="true" | |
android:layout_alignParentRight="true" | |
android:background="?attr/selectableItemBackgroundBorderless" | |
android:src="@drawable/ic_favorite_border" | |
android:layout_below="@id/img" | |
android:layout_marginRight="5dp" | |
android:layout_marginEnd="5dp" | |
android:contentDescription="FavButtonDesc" /> | |
</RelativeLayout> | |
</android.support.v7.widget.CardView> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment