我試圖用OvalShape繪製自定義ShapeDrawable,並用白色和灰色邊框填充。我創建像這樣的繪製:在Android上繪製具有邊框(圓角半徑)的以編程方式呈橢圓形狀
ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
drawable.getPaint().setColor(Color.GRAY);
drawable.getPaint().setStyle(Style.STROKE);
drawable.getPaint().setStrokeWidth(getPixels(5));
drawable.getPaint().setAntiAlias(true);
但後來的結果:corners problem
的想法是通過編程來創建一個形狀像這樣的,但不同的顏色:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip"/>
<stroke android:color="#FF0000" android:width="5dip"/>
<solid android:color="@android:color/transparent"/>
</shape>
如何解決這個問題?
你是說,問題是鏈接圖像中顯示的邊框的剪裁? – 2013-03-06 12:55:57
是的!如果筆畫寬度爲0(髮際線),但沒有解決方案對我來說沒有問題。順便說一句getPixels()方法會返回像素,但我認爲這不是問題。 – L3K0V 2013-03-06 13:07:19
我認爲問題在於你的drawable的大小。您需要減小尺寸以適應邊框的寬度。 – 2013-03-06 13:35:46