2014-10-01 22 views
13
ben xml ile bunu yapmanın bir yolu var mı bu bir

Android - xml

enter image description here

gibi benim şekil için bir düğme yapmak istiyorum

ile bir ok şeklini yapmak? bazı noktalarını ayarlama gibi benim durumumda ben ne gerek projenizin drawable-xxx klasörde shape xml file oluşturmak ve daha sonra bir düğme için arka plan olarak bu şekil kullanmaktır 5 ..

+0

Arka plan düzeni dinamikse, beyaz şeridini [! [Resim açıklaması buraya girin] (http://i.stack.imgur.com/FKtR1.png)] (http: //i.stack) gösterir. imgur.com/FKtR1.png) –

cevap

20

var. İşte

denilen şekil dosyası arrow_shape.xml geçerli:

enter image description here

: Örneğin İşte

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

için,

<?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="#5EB888" /> 
     <corners android:radius="0dp"/> 
    </shape> 
</item> 

<!-- This rectangle for the top arrow edge --> 
<!-- Its color should be the same as the layout's background --> 
<item 
    android:top="-40dp" 
    android:bottom="65dp" 
    android:right="-30dp"> 
    <rotate 
     android:fromDegrees="45"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#ffffff" /> 
     </shape> 
    </rotate> 
</item> 

<!-- This rectangle for the lower arrow edge --> 
<!-- Its color should be the same as the layout's background --> 
<item 
    android:top="65dp" 
    android:bottom="-40dp" 
    android:right="-30dp"> 
    <rotate 
     android:fromDegrees="-45"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#ffffff" /> 
     </shape> 
    </rotate> 
</item> 

</layer-list> 
Sonra

düğmenin arka plan olarak kullanmak ekran görüntüsü

Layer-List hakkında daha fazla bilgi here bulabilirsiniz.

DÜZENLEME:

Ben şeklin genişlik ve yükseklik belirli değerler kullanılana olsa unutmayın. Bunları değiştirirseniz, top, bottom and right attributes'un değerlerini değiştirmeniz gerekebilir. Yani, bu durumda projenizin values dizinindeki farklı değerleri kullanmayı düşünün.

İlgili konular