在图像视图顶部绘制圆形
问题描述:
当前位于视图上,我有一个ImageView和一个在视图上绘制圆的自定义类。它将在视图上画圆,但它隐藏在图像视图后面。我知道它的存在,因为当半径足够大时,我可以看到一个不在imageview后面的小部分。什么代码会把它带到前面?在图像视图顶部绘制圆形
编辑:发现上述问题不是问题。它似乎只是在为视图上的搜索栏保留的部分上绘制它?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_process);
mDraw = new Draw(this);
addContentView(mDraw, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
b = (Button) findViewById(R.id.button1);
seekBar1.setMax(500);
seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
mDraw.setCords(500, 500, seekBar1.getProgress());
}
public void onStartTrackingTouch(SeekBar seekBar) {
mDraw.setCords(500, 500, seekBar1.getProgress());
}
public void onStopTrackingTouch(SeekBar seekBar) {
mDraw.setCords(500, 500, seekBar1.getProgress());
}
});
}
这里是绘制类:
package org.DTS.boltsize;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
public class Draw extends View {
private int x = 1;
private int y = 1;
private int r = 1;
public Draw(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public void setCords(int mx, int my, int mr){
x = mx;
y = my;
r = mr;
}
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
System.out.println("Drew :)");
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
canvas.drawCircle(x, y, r, paint);
super.onDraw(canvas);
}
public void DrawCirlce(Canvas canvas, int x, int y, int r){
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GREEN);
canvas.drawCircle(x, y, r, paint);
super.onDraw(canvas);
}
}
这里是什么样子。这个红圈应该覆盖整个屏幕。
答
通过将源代码转换为位图来解决,然后在该位图上绘制一个圆圈并将最终的位图发送到imageview。
答
我会绘制到一个单独的位图,你有不同的imageView在相同的空间,你可能在一个FrameLayout你的位图位图。然后您可以使用.bringToFront来决定z顺序。
你在画什么?一个背景图位图?另一个图像视图? – Ifor 2012-01-03 23:02:08
绘制整个活动视图。 – 2012-01-03 23:06:06