2016-06-15 54 views
1

我想创建XML drawble这种形状,任何人都可以帮我,如何创建这种形状drawble

enter image description here

+0

岂不是更好地使用9修补图像? –

+0

对于这种复杂的形状它的面糊使用图像作为9补丁图像https://developer.android.com/studio/write/draw9patch.html –

+0

使用9补丁图像解决问题,谢谢Pankaj和Ajay –

回答

2

使用此布局,并保存在文件夹绘制.....

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item> 
     <shape android:shape="rectangle"> 
      <size 
       android:width="200dp" 
       android:height="50dp" /> 
      <solid android:color="#ef45d1" /> 
      <corners android:topRightRadius="20dp" /> 
     </shape> 
    </item> 


    <item 
     android:bottom="0dp" 
     android:right="165dp" 
     android:top="0dp"> 

     <rotate 
      android:fromDegrees="45" 
      android:pivotX="0%" 
      android:pivotY="0%" 
      android:toDegrees="45"> 

      <shape android:shape="rectangle"> 
       <solid android:color="#ffffff" /> 


      </shape> 
     </rotate> 

    </item> 

</layer-list> 

,并在布局视图背景设置....

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:background="@drawable/newrecatngle"/> 

注: - 设置宽度和高度WRAP_CONTENT .....

Image

享受编码...........

+0

感谢您的努力sushildlh,但我需要使白色三角形透明,是否有可能做这样的事情.. –

+0

只是改变这种颜色到你的背景'' – sushildlh

+0

当我做到这一点,底部的粉红色方形部分将出现,我不会让它透明而不这样做。 –