开发者

How to assign photo in .java file to an ID in XML file for Android App

Im trying to assign a picture in my .java file to one of my IDs开发者_如何学Python in the xml file. Can anyone show me some code that would help me with this? Thanks


Load the proper resource file using setContentView(R.layout.layout_of_activity)

Then, make an ImageView object and use the findViewById method by passing it the ID of the image that you assigned it from the xml file, i.e.

setContentView(R.layout.main);
ImageView picture = (ImageView) findViewById(R.id.pic_id);

Then you can do whatever you want with the pic like,

picture.setImageResource(R.drawable.picture_png);

Try checking out the android api samples to see how to do some more complex image manipulation like animating or rotating

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜