Reputation: 785
hi i am adding some images dynamically through touch event. that is, where ever i touch and click add image, image is added to that position. when i change from portrait to landscape the position of the image should be adjusted accordingly.. for that i am setting the margins and adjusting the position of the image. but, this is possible only one side. Like, if i add images in portrait mode. i will apply scaling and adjust it when configuration changes to landscape. but, if i want to add images in landscape the position of the image is not added to the particular position where i touch. how do i resolve this. kindly help me out. Here is the piece of code i am sharing
public void AddButtons(int id) {
int x = Integer.parseInt(StickyNotesList.get(id).getX());
int y = Integer.parseInt(StickyNotesList.get(id).getY());
float scale=pageViewManager.mDocument.getmPageSizeY()/pageViewManager.mDocument.getPageheight();
RelativeLayout r=new RelativeLayout(stickynoteContext);
/*AbsoluteLayout r = new AbsoluteLayout(stickynoteContext);
AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(pageViewManager.mDocument.mPageSizeX,pageViewManager.mDocument.mPageSizeY, (int) (x*scale), (int)(y*scale-(pageViewManager.getTitleViewHeight())));*/
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(pageViewManager.mDocument.mPageSizeX,pageViewManager.mDocument.mPageSizeY);
params.setMargins(x*scale, y*scale-pageViewManager.getTitleViewHeight(), 0, 0);
r.setLayoutParams(params);
final Button btn = new Button(stickynoteContext);
Drawable BG1 = (Drawable) getResources()
.getDrawable(R.drawable.stickynote_icon);
btn.setBackgroundDrawable(BG1);
btn.setWidth((int)(stickynoteImag_Width*scale));
btn.setHeight((int)(stickynoteImag_Height*scale));
btn.setId(id+1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
updateStickyNotes(btn.getId());
}
});
r.addView(btn);
this.addView(r);
StickyNoteLayout.add(r);
r.invalidate();
StickyNoteLayout.get(id).invalidate();
}
Upvotes: 0
Views: 813
Reputation: 4102
While changing the orientation, OS restarts the activity, so if you want to handle the orientation change you should check the orientation. There is a sample code here http://www.southparksystems.com/devzilla/2010/3/3/switching-layouts-when-screen-orientation-changes-in-android.html
Upvotes: 1