2012-04-23 25 views
0

ImageButtonをx、yの位置に配置したいと考えています。 問題は、Androidが画像の周囲にパディングを追加することです。 パディングの正確なサイズがわからないので、正確な位置にイメージボタンを配置できません。 パディングを削除したいと思います。 イメージの周りのパディングをプログラムで削除するにはどうすればよいですか? button.setPadding(0、0、0、0)ボタンの幅をビットマップより短く、高さを長くします。 button.getLayoutParams()。widthはマイナスの値を返します。 私がこれまでに試したのはこれのようなものです。x、y位置にImageButtonを配置する方法は?

protected class MyLayout extends RelativeLayout { 
    Bitmap img; 
    ImageButton button; 

    public MyLayout(Context context) { 
     button = new ImageButton(context); 
     img = BitmapFactory.decodeResource(getResources(), R.drawable.img); 
     button.setImageBitmap(img); 
     params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     button.setLayoutParams(params); 
     params.setMargins(x, y, 0, 0); 
     button.setBackgroundDrawable(null); 
     addView(button, params); 
    } 
}  

答えて

0

EDIT

これを使用して...

 MarginLayoutParams marginParams = new MarginLayoutParams(image.getLayoutParams()); 
    int left = someValue; 
    int top = someValue; 
    marginParams.setMargins(left, top, 0, 0); 
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams); 
    image.setLayoutParams(layoutParams); 
+0

が、どのように彼は同じparams.setMarginsを使用して、特定の場所で –

+0

それを設定することができます(X、Y、0、0 ); –

+0

それから、それを削除する理由は –

関連する問題