1
我已經搜索EVERYWHERE爲這個答案。自定義Drawables與android
我想了解如何繪製一個自定義形狀在xml中製作成位圖或畫布。
這是我的矩形簡單的xml代碼。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#f0f000" />
<stroke android:width="3dp" android:color="#ff0000" />
</shape>
然後在這裏,我試圖簡單地獲取形狀並將其放在位圖上,然後將該位圖繪製到畫布上?
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.shape);
canvas.drawBitmap(myBitmap, canvas.getHeight() /2, canvas.getWidth()/2, p);
如果有人能幫助,我會非常感激。