Android: Button with two images | alignment -


i have created button programmatically , able set icon on using below code

enter image description here

drawable icon = context.getresources().getdrawable(iconresourceid); button.setcompounddrawableswithintrinsicbounds(icon, null, null, null); 

now, want have image (icon) on right top corner, please see below image:

enter image description here

i have tried add both images, using below code:

drawable icon = context.getresources().getdrawable(iconresourceid); drawable icon2 = context.getresources().getdrawable(iconresourceid2); button.setcompounddrawableswithintrinsicbounds(icon, null, icon2, null); 

and, getting below results:

enter image description here

can please tell me, how can align right top corner?

your code btn_background background have @ moment

    button button = new button(this);     drawable icon = context.getresources().getdrawable(iconresourceid);     button.setcompounddrawableswithintrinsicbounds(icon, null, null, null);     button.settext("test");      if (hasnewupdates()) {         button.setbackgroundresource(r.drawable.btn_background_with_icon);     } else {         button.setbackgroundresource(r.drawable.btn_background);     } 

and how btn_background_with_icon like

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">      <item android:drawable="@drawable/btn_background"/>     <item android:gravity="right" android:bottom="72dp" android:drawable="@drawable/ico_info"/> </layer-list> 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -