How do I draw an arrowhead (in Android)?

后端 未结 8 529
一个人的身影
一个人的身影 2020-11-29 06:29

I\'m fairly new to Android and have been toying around with Canvas. I\'m attempting to draw an arrow but I\'m only having luck with drawing the shaft, none of the arrowhead

8条回答
  •  醉话见心
    2020-11-29 07:11

    I've been having the same problem, I need an arrow to point in a certain direction. After playing around with drawing algorithms I decided the simplest method is to use a bitmap & simply use a Matrix to rotate it, e.g.

    ImageView image = (ImageView) findViewById(R.id.bitmap_image);
    Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.test);
    Matrix mat = new Matrix();
    mat.postRotate(90);
    Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), mat, true);
    image.setImageBitmap(bMapRotate);
    

    then your bitmap can be any fancy looking arrow you like.

提交回复
热议问题