开发者

can anyone suggest a good tutorial on drawing shapes onto a SurfaceView? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 8 years ago.

Improve this question 开发者_高级运维

I'm spinning my wheels trying to draw some shapes on the screen and failing. I have a SurfaceView class that I have set as my contentview and am trying to draw an oval in its onSurfaceCreated call, but nothing is being drawn.

It's entirely possible that I'm not understanding the whole nature of the enterprise. My understanding is that the Surface is basically a blank slate onto which I can draw whatever I like.

Here's my code (I don't necessarily want to "fix" this code, rather than do this the "right" way, whatever that is..., just can't find the docs that explain this. I don't want (or need) OpenGL, just want to draw shapes, text etc manually.

This code runs (without failing), but nothing gets drawn.

TIA

    public class main extends Activity {
    /** Called when the activity is first created. */
    public  Context c;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(new Surf(this));
    }
}

class Surf extends SurfaceView implements SurfaceHolder.Callback {
    SurfaceHolder mHolder;
    Canvas can;
    Context c;
    private ShapeDrawable mDrawable;

    SynField(Context context) {
        super(context);

        c = context;

        this.layout(20, 20, 660, 500);
        mHolder = getHolder();
        //mHolder.addCallback(this);
        //mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        Log.d("MY_DEBUG", "drawing");
        can = mHolder.lockCanvas();

        int x = 10;
        int y = 10;
        int width = 300;
        int height = 50;

        mDrawable = new ShapeDrawable(new OvalShape());
        mDrawable.getPaint().setColor(0xcccccccc);
        mDrawable.setBounds(x, y, x + width, y + height);


    }



    public void surfaceCreated(SurfaceHolder holder) {
        Log.d("MY_DEBUG", "surface drawn");
        mDrawable.draw(can);

    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub

    }
}


http://www.droidnova.com/playing-with-graphics-in-android-part-ii,160.html http://www.devdaily.com/java/jwarehouse/android/core/java/android/view/SurfaceView.java.shtml

These might help...

I think you can try doing it by using Paint class in android sdk. can do something like:

Paint mypaint = new Paint(); Canvas c = new Canvas(); c.drawLine(10,10,20,20,mypaint);


try these
http://www.droidnova.com/playing-with-graphics-in-android-part-ii,160.html
http://developer.android.com/guide/topics/graphics/index.html


I learned a lot following this tutorial, on how to create a drawing app. I believe it will help:

http://mobile.tutsplus.com/tutorials/android/android-sdk-create-a-drawing-app-interface-creation/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜