Drawing Nine Patch onto Canvas (Android)

前端 未结 1 488
温柔的废话
温柔的废话 2021-01-30 11:25

I\'m trying to draw a nine patch onto a Canvas object on the Android. What seems strange is that although I generated my nine patch using the draw9patch tool, the constructor fo

相关标签:
1条回答
  • 2021-01-30 12:12

    You can easily do it this way:

    // Load the image as a NinePatch drawable
    NinePatchDrawable npd = (NinePatchDrawable)Resources.getDrawable(R.drawable.my_nine_patch);
    
    // Set its bound where you need
    Rect npdBounds = new Rect(...);
    npd.setBounds(npbBounds);
    
    // Finally draw on the canvas
    npd.draw(canvas);
    
    0 讨论(0)
提交回复
热议问题