As a friend of Android developers know, we can use this to set the top of the button or (bottom, left, right) picture resources in XML:
So what if you need to configure the picture dynamically? We have to use Java code to do this:
Drawable drawable =NULL;d rawable=splash.contexttools.getresources (). getdrawable (R.drawable.pepper);//Get Drawable ObjectDrawable.setbounds (0, 0, 24,75);//set the width and height of a drawable objectNew_button.setcompounddrawables (NULL,NULL, Drawable,NULL);//put the Drawable object on the right side of the New_button (here is a note, if you use the Setcompunddrawables method, you must first configure a resource through SetBounds)new_button.setcompounddrawablepadding (35);//set the spacing between drawable and New_button
Through the above code, we basically meet the needs of our use.
Some students will ask, if I want to ensure that the original size of the picture what to do?
Setcompounddrawableswithintrinsicbounds (null,null,drawable,null);//This method can use the intrinsic width and height of the picture
OK, next time we share the other
4. Dynamic configuration of Drawabletop (Drawableboottom, Drawableleft, drawableright) in Java code in Android XML