2012-06-14 6 views
0

가로줄이 각각 1dp 인 드로어 블을 만들려고합니다. 나머지는 각각 다른 색을 사용해야하며 나머지는 공간이 있어야합니다. 그라데이션 가득 :모양 선은 항상 XML 드로어 블에서 검정색입니다.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="line"> 
      <stroke android:width="1dp" android:color="#c80047"/> 
     </shape> 
    </item> 
    <item android:top="1dp"> 
     <shape android:shape="line" > 
      <stroke android:width="1dp" android:color="#5ec800"/> 
     </shape> 
    </item> 
    <item android:top="2dp"> 
     <shape android:shape="line" > 
      <stroke android:width="1dp" android:color="#ffffff"/> 
     </shape> 
    </item> 
    <item android:left="0dp" android:right="0dp" android:top="3dp"> 
     <shape android:shape="rectangle"> 

      <gradient android:angle="-90" android:startColor="#3B3B3B" 
       android:endColor="#000000" /> 

     </shape> 
    </item> 

</layer-list> 

기울기가 제대로 그려하지만 3 라인 블랙으로 유지 :

The grey part represent the gradient

그래서 난이 썼다. 결과가 <stroke android:color="a_color" /> 인 것을 추가하려고했습니다.

무엇이 누락 되었습니까?

답변

1

그 선이 그려집니다하지만 그들은 당신이 그들이 생각 상단에 있지 그려 (당신이 가진 사각형이를 볼 수 있습니다 어떤 선 모양보다 앞에있는 그라디언트) 마지막 항목 인 그라데이션 사각형으로 덮여 있습니다. 답변에 대한

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item> 
     <shape> 
      <solid android:color="#c80047" /> 

      <size android:height="1dp" /> 
     </shape> 
    </item> 
    <item android:top="1dp"> 
     <shape> 
      <solid android:color="#5ec800" /> 

      <size android:height="1dp" /> 
     </shape> 
    </item> 
    <item android:top="2dp"> 
     <shape> 
      <solid android:color="#ffffff" /> 

      <size android:height="1dp" /> 
     </shape> 
    </item> 
    <item 
     android:left="0dp" 
     android:right="0dp" 
     android:top="3dp"> 
     <shape android:shape="rectangle" > 
      <gradient 
       android:angle="-90" 
       android:endColor="#000000" 
       android:startColor="#3B3B3B" /> 
     </shape> 
    </item> 

</layer-list> 
+0

감사 :

는 당신이 시도 할 수있는 당김을 확인하십시오. 솔루션을 사용하면 두 번째 줄은 2dp이고 첫 번째와 세 번째 줄은 1dp입니다. 나는 같은 문제를 shape = "rectangle"을 사용한다. 내 애플 리케이션에서 exemple 추출물이 여기에 표시됩니다 : http://hpics.li/437e8e4 (저장 및 확대/축소) – grunk

+0

@grunk 그림을 본 적이 있지만 그 줄의 크기 때문에 발생한다고 생각합니다. '1dp'는 전화 화면에서 실제로 작습니다. 사용자는 각 줄 크기를 보지 않고, 거기에 뭔가 있다는 것을 간신히 알 수 있습니다.) 어쨌든, 내 코드를 테스트했는데 더 큰 차원을 사용하면 (실제로 10dp를 사용하여 선을 더 잘 보았을 때) 선이 같은 크기이고 선이 똑같은 높이를 갖습니다. – Luksprog

+0

이것에 대해 더 알고 싶습니까? : http : //stackoverflow.com/questions/19166342/how-do-i-avoid-double-borders-between-lists/19201562? noredirect = 1 # comment28459924_19201562 –

0

모든 세 줄이 가운데 정렬되어있어 중력을 설정하는 매개 변수가 없습니다. 나는 그 라인을 rectange로 또한 갈 것이다. 마지막 항목을 이동하는 경우 대신 그들이 당김의 중심에 그려,

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="#c80047"/> 
     </shape> 
    </item> 
     <item android:top="1dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#5ec800"/> 
     </shape> 
    </item> 
    <item android:top="2dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#ffffff"/> 
     </shape> 
    </item> 
    <item android:left="0dp" android:right="0dp" android:top="3dp"> 
     <shape android:shape="rectangle"> 
      <gradient android:angle="-90" android:startColor="#3B3B3B" 
       android:endColor="#000000" /> 
     </shape> 
    </item> 
</layer-list>