0
が、私はそうのようなプログラム的サークルビットマップを生成した:プログラムで生成されたビットマップをビューに配置するにはどうすればよいですか?
private Bitmap drawDotCircle() {
int circleSize = 100;
circleBitmap = Bitmap.createBitmap(
circleSize,
circleSize,
Bitmap.Config.ARGB_8888
);
canvas = new Canvas(circleBitmap);
CanvasRadius = Math.min(canvas.getWidth(), canvas.getHeight()/2);
// Create a Paint object used to paint the circle
paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
paint.setAntiAlias(true);
canvas.drawCircle(
canvas.getWidth()/2,
canvas.getHeight()/2,
CanvasRadius - CanvasPadding,
paint
);
return circleBitmap;
}
私は私が計算してきた絶対的なXとYでそれを配置したいと思います。
int dotX =getResources().getDisplayMetrics().widthPixels/2;
int dotY = getResources().getDisplayMetrics().heightPixels/2;
円がビューの中央に表示されるようにするにはどうすればよいですか?私は、次のコードを試してみましたが、円が何らかの理由でオフセンター常にある:
RelativeLayout.LayoutParams layoutParams =
new RelativeLayout.LayoutParams(circleDot.getHeight(), circleDot.getHeight());
// Setting position of our ImageView
layoutParams.leftMargin = dotX;
layoutParams.topMargin = dotY;
// Finally Adding the imageView to RelativeLayout and its position
relativeLayout.addView(dotView, layoutParams);
これでも画像を中央に配置することはできません。次は、オリジナルのx&y計算を使用して配置された赤い点のスクリーンショットです:http://i.imgur.com/t8VGB7c.jpg、次に示唆された計算のスクリーンショット:http://i.imgur.com /V9X2zdW.jpgどちらの場合も、ドットは中心から外れています – damememan