Skip to content

Instantly share code, notes, and snippets.

@eugenebrusov
Last active November 14, 2017 10:12
Show Gist options
  • Save eugenebrusov/7175459cfb05785c69aab2feff783cee to your computer and use it in GitHub Desktop.
Save eugenebrusov/7175459cfb05785c69aab2feff783cee to your computer and use it in GitHub Desktop.
CardView - avatar, media 16:9 and action buttons
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/avatar_image"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="12dp"
android:layout_marginStart="12dp"
android:padding="4dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_avatar_40dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/media_image"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/title_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="16dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="#DE000000"
app:layout_constraintTop_toTopOf="@+id/avatar_image"
app:layout_constraintStart_toEndOf="@+id/avatar_image"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/subtitle_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="4dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="#8A000000"
app:layout_constraintStart_toEndOf="@+id/avatar_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/avatar_image" />
<ImageView
android:id="@+id/media_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="12dp"
android:scaleType="centerCrop"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintTop_toBottomOf="@+id/avatar_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/action_button_1" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:id="@+id/action_button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:minWidth="0dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textColor="#DE000000"
app:layout_constraintTop_toBottomOf="@+id/media_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/action_button_2" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:id="@+id/action_button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:minWidth="0dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textColor="#DE000000"
app:layout_constraintTop_toBottomOf="@+id/action_button_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40.0"
android:viewportHeight="40.0">
<path
android:pathData="M20,20m-20,0a20,20 0,1 1,40 0a20,20 0,1 1,-40 0"
android:fillColor="@android:color/darker_gray" />
</vector>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment