2014-10-01 4 views
13
내가 XML을이 할 수있는 방법이 있나요이 하나

안드로이드 - XML ​​

enter image description here

처럼 내 모양의 버튼을 만들고 싶어

과 화살표 모양을? 몇 가지 포인트를 설정처럼, 내 경우에는 내가 당신이 필요로하는 프로젝트의 drawable-xxx 폴더에 shape xml file을 만든 다음 버튼을 배경으로이 모양을 사용하는 것입니다 오 ..

+0

배경이 동적 인 레이아웃 인 경우 흰색 레인 [! [이미지 설명 입력] (http://i.stack.imgur.com/FKtR1.png)] (http : //i.stack. imgur.com/FKtR1.png) –

답변

20

있습니다. 여기

라는 모양 파일 arrow_shape.xml입니다 :

enter image description here

: 예 여기

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

를 들어,

<?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> 
다음

버튼의 배경으로 사용하면 스크린 샷입니다

Layer-List에 대한 자세한 정보는 here입니다.

는 편집 :

내가 모양의 폭과 높이에 대한 특정 값을 사용하는하지만 명심하십시오. 이들을 변경하면 top, bottom and right attributes의 값을 변경해야 할 수도 있습니다. 따라서이 경우 프로젝트의 values 디렉토리에서 다른 값을 사용하는 것이 좋습니다.