Im trying to assign a picture in my.java file to one of my IDs 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, ie
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.