Created
July 22, 2014 22:16
-
-
Save DanielGrech/ba452416c1919ee69932 to your computer and use it in GitHub Desktop.
List item for displaying 2 lines of text with an image to the right
This file contains hidden or 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
<dimen name="li_primary_text_size">18sp</dimen> | |
<dimen name="li_secondary_text_size">14sp</dimen> |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<components.android.dgsd.com.componentstest.TestListItem | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center_vertical" | |
android:paddingTop="8dp" | |
android:paddingBottom="8dp" | |
android:paddingLeft="@dimen/default_padding" | |
android:paddingRight="@dimen/default_padding"> | |
<ImageView | |
android:id="@+id/image" | |
android:layout_width="48dp" | |
android:layout_height="48dp" | |
android:scaleType="fitCenter" | |
android:layout_alignParentRight="true" | |
android:layout_centerVertical="true"/> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_centerVertical="true" | |
android:layout_toLeftOf="@+id/image" | |
android:orientation="vertical"> | |
<TextView | |
android:id="@+id/primary" | |
style="@style/ListItemText.Primary"/> | |
<TextView | |
android:id="@+id/secondary" | |
style="@style/ListItemText.Secondary"/> | |
</LinearLayout> | |
</components.android.dgsd.com.componentstest.TestListItem> |
This file contains hidden or 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
<style name="ListItemText"> | |
<item name="android:layout_width">match_parent</item> | |
<item name="android:layout_height">wrap_content</item> | |
<item name="android:fontFamily">sans-serif-light</item> | |
<item name="android:singleLine">true</item> | |
<item name="android:maxLines">1</item> | |
<item name="android:ellipsize">end</item> | |
</style> | |
<style name="ListItemText.Primary" parent="ListItemText"> | |
<item name="android:textSize">@dimen/li_primary_text_size</item> | |
<item name="android:textColor">@color/dark_text</item> | |
</style> | |
<style name="ListItemText.Secondary" parent="ListItemText"> | |
<item name="android:textSize">@dimen/li_secondary_text_size</item> | |
<item name="android:textColor">@color/light_text</item> | |
</style> |
This file contains hidden or 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
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.view.LayoutInflater; | |
import android.view.ViewGroup; | |
import android.widget.ImageView; | |
import android.widget.RelativeLayout; | |
import android.widget.TextView; | |
import butterknife.ButterKnife; | |
import butterknife.InjectView; | |
public abstract class TwoLineImageListItem<D> extends RelativeLayout { | |
@InjectView(R.id.image) | |
ImageView mImage; | |
@InjectView(R.id.primary) | |
TextView mPrimary; | |
@InjectView(R.id.secondary) | |
TextView mSecondary; | |
public abstract void populate(D data); | |
public static <T extends TwoLineImageListItem> T inflate(ViewGroup parent, Class<T> cls) { | |
return (T) LayoutInflater.from(parent.getContext()) | |
.inflate(R.layout.li_two_line_image, parent, false); | |
} | |
public TwoLineImageListItem(Context context) { | |
super(context); | |
} | |
public TwoLineImageListItem(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public TwoLineImageListItem(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
@Override | |
protected void onFinishInflate() { | |
super.onFinishInflate(); | |
ButterKnife.inject(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment