android - ImageButton stretch src to fill -
this question comes quite often, in examples have found, image src defined in xml. e.g android:src="..."
my code doesn't specificy src untill activity, using imagebutton.setimageresource() single button, performing play/stop
how fill imagebutton src, when src defined later?
i tryed imagebutton.setscaletype="fitxy", sdk doesn't using string...
update: after trying utilize suggested below, problem still occurs. here more explanation help
<imagebutton android:id="@+id/imgstart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> public class mainactivity extends activity{ private imagebutton player; protected void oncreate(){ player = (imagebutton) findviewbyid(r.id.imgstart); ... if(isplaying){ player.setimageresource(bitmap image); } else{ player.setimageresource(different bitmap image); } ... }
please seek below code set scaletype programatically
imagebutton object".setscaletype(scaletype.fit_xy) "imagebutton object" should object of class imagebutton (that defined in xml).
android android-imagebutton
No comments:
Post a Comment