简体   繁体   中英

Image(s) placement over a image in Android

I was attempting to place a image on top of another existing image in android. Here was the game plan. First the user would select a button and then that button would tell the program to populate a sprite/ image to a fixed location on the master Image. Once the image is set the user could then hit a button for another image on top of what is currently their, (the goal is two images with a option to change their size, x and y position. I am only using android 2.1 platform! The button for selection and the text describing the activity are in a linearlayout.

You should use a RelativeLayout and then you can use params to set position, margin, etc.. something like this:

//this is your fist item
r1.setImageResource(R.drawable.myimage);

//this is the second item
r2.setImageResource(R.drawable.myimage2);

RelativeLayout.LayoutParams imageParams=
new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageParams.setMargins(1, 1, 1, 1);
imageParams.addRule(RelativeLayout.BELOW,r1.getId());
addView(r2,imageParams);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM