我在项目中添加了一个按钮和一个点,并将点和按钮放在相对布局中,并将它们设置为与此代码相同的参数:
rllp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
rllp.topMargin = 0 ;
rllp.leftMargin = 0 ;
rllp2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
rllp2.topMargin = 0 ;
rllp2.leftMargin = 0 ;
drawingImageView = (ImageView) this.findViewById(R.id.DrawingImageView);
Bitmap bitmap = Bitmap.createBitmap((int) getWindowManager()
.getDefaultDisplay().getWidth(), (int) getWindowManager()
.getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawingImageView.setImageBitmap(bitmap);
Paint paint = new Paint();
paint.setStrokeWidth(6);
drawingImageView.setLayoutParams(rllp);
canvas.drawPoint(0, 0, paint);
btn = (Button) findViewById(R.id.button1);
btn.setLayoutParams(rllp2);
但结果不是我想要的!!按钮和点不在同一位置......我打算将它们都放在(0,0)中。 我认为问题在于:
Bitmap bitmap = Bitmap.createBitmap((int) getWindowManager()
.getDefaultDisplay().getWidth(), (int) getWindowManager()
.getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
但是我没有任何解决方案......我怎样才能在一个地方设定位置? 它是结果的图片: http://i.stack.imgur.com/IWx7V.png 我想把点放在按钮的左上角。