2011-04-12 107 views
0

嗨 我通過觸摸事件動態添加一些圖像。也就是說,只要我觸摸並點擊添加圖像,圖像就會添加到該位置。當我從肖像更改爲風景時,應該相應地調整圖像的位置。爲此,我設置邊距並調整圖像的位置。但是,這可能只有一面。就像,如果我以肖像模式添加圖像。我將應用縮放並在配置更改爲橫向時對其進行調整。但是,如果我想在橫向上添加圖像,圖像的位置不會添加到我觸摸的特定位置。我該如何解決這個問題。請幫助我。下面是一段代碼,我正在分享如何設置從橫向更改肖像模式的圖像的位置android

公共無效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(); 
     } 

回答

相關問題