2017-08-27 94 views
0

我想繪製一個只有頂部和底部邊緣的矩形,但刪除矩形的左側和右側邊緣可能會嘗試在代碼行下方,但它不能正常工作我如何移除矩形的左右邊緣。如何繪製頂部和底部邊緣的矩形

實際Rectangel

enter image description here

預計矩形

enter image description here

代碼:

canvas.clipRect(10, 0, 200, 200, Region.Op.DIFFERENCE); 
canvas.drawRect(10, 10, 200, 200, paint); 

在這裏,可能會刪除頂部邊緣,但我不知道如何使矩形像期待任何人都可以幫助我。

+1

爲什麼你不只是畫兩條線? –

+0

我正在使形狀發光,所以左右兩邊都用左右邊緣的設備展開,所以我想去除這兩個邊緣。只需要處理上下邊緣。 –

回答

0

這樣做。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="#0000ff" /> 
    </shape> 
</item> 
<item android:bottom="10dp" android:top="10dp" > 
    <shape android:shape="rectangle"> 
     <solid android:color="#FFFF" /> 
    </shape> 
</item> 
</layer-list> 

輸出是這樣的:

enter image description here

+0

同樣的事情如何實現成使用canvas的Android –

相關問題