Skip to content

Instantly share code, notes, and snippets.

@DanielGrech
Created July 24, 2014 20:51
Show Gist options
  • Save DanielGrech/e0734adc27a614569873 to your computer and use it in GitHub Desktop.
Save DanielGrech/e0734adc27a614569873 to your computer and use it in GitHub Desktop.
Layout for an image with 2 labels at the bottom. Overlay is applied to bleed out any images
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:layout_height="200dp" />
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/overlay_gradient" />
<LinearLayout
android:id="@+id/text_wrapper"
style="@style/ImageWithOverlappingLabel.Label.Wrapper">
<TextView
android:id="@+id/text1"
style="@style/ImageWithOverlappingLabel.Label.Title" />
<TextView
android:id="@+id/text2"
style="@style/ImageWithOverlappingLabel.Label.Subtitle" />
</LinearLayout>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#88000000"
android:endColor="#33000000"
android:angle="90"
android:type="linear" />
</shape>
<style name="ImageWithOverlappingLabel" />
<style name="ImageWithOverlappingLabel.Label.Wrapper">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_gravity">bottom</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
</style>
<style name="ImageWithOverlappingLabel.Label">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:maxLines">1</item>
<item name="android:ellipsize">end</item>
</style>
<style name="ImageWithOverlappingLabel.Label.Title" parent="ImageWithOverlappingLabel.Label" >
<item name="android:textStyle">bold</item>
</style>
<style name="ImageWithOverlappingLabel.Label.Subtitle" parent="ImageWithOverlappingLabel.Label" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment