2015-10-19 97 views
2

有沒有什麼方法可以在android xml中繪製單邊的角矩形。像下面這個圖片...在android xml中的一邊角矩形

enter image description here

+0

不要使用該XML,它是沒有意義的,而不是使用'ShapeDrawable'與自定義'Shape'類 – pskink

+0

原諒我,但形狀不顯示我的屏幕爲矩形,它出現作爲其中兩個邊平行並且兩個角是直角的四邊形。 –

回答

2

可以使用下面的XML代碼來實現。唯一的缺點是第二個矩形應該與背景的顏色相匹配。

<?xml version="1.0" encoding="UTF-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
     <!-- Colored rectangle--> 
     <item> 
      <shape android:shape="rectangle"> 
       <size 
        android:width="100dp" 
        android:height="40dp" /> 
       <solid android:color="#F00" /> 
      </shape> 
     </item> 

<!-- Overlay with same color as background--> 
    <item 
     android:top="20dp" 
     android:bottom="-40dp" 
     android:right="-30dp"> 
     <rotate 
      android:fromDegrees="-60"> 
      <shape android:shape="rectangle"> 
       <solid android:color="#FFF" /> 
      </shape> 
     </rotate> 
    </item> 
</layer-list>