Skip to content

Instantly share code, notes, and snippets.

@Kuchinashi
Created August 8, 2014 00:06
Show Gist options
  • Save Kuchinashi/3b816e4c3272ba449c34 to your computer and use it in GitHub Desktop.
Save Kuchinashi/3b816e4c3272ba449c34 to your computer and use it in GitHub Desktop.
画像を重ねて表示する ref: http://qiita.com/kuchinashi_r/items/eca7107914e00262d241
Context appContext = getApplicationContext();
ImageView image = new ImageView(appContext);
BitmapDrawable newIcon = (BitmapDrawable) getResources().getDrawable(R.drawable.new_icon);
newIcon.setGravity(Gravity.LEFT | Gravity.TOP);
Drawable[] drawables = {
getResources().getDrawable(R.drawable.twitter),
newIcon
};
LayerDrawable ld = new LayerDrawable(drawables);
image.setImageDrawable(ld);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(WC, WC);
lp.addRule(RelativeLayout.ALIGN_TOP | RelativeLayout.ALIGN_LEFT);
mRootLayout.addView(image, lp);
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/twitter">
<bitmap android:src="@drawable/twitter" />
</item>
<item
android:id="@+id/new_icon"
android:left="50dp">
<bitmap
android:gravity="top|left"
android:src="@drawable/new_icon" >
</bitmap>
</item>
</layer-list>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment