2012-06-19 4 views
29

listview 분배 자로 여백을 설정하려고합니다.
디바이더는 점선이다Listview divider margin


<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="line" > 
    <stroke 
     android:dashGap="1dp" 
     android:dashWidth="1.5dp" 
     android:width="1dp" 
     android:color="#FF404040" /> 

    <size android:height="3dp" /> 

</shape> 
내가 디바이더

<ListView 
    android:id="@+id/lv_news_feed_list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" 
    android:divider="@drawable/ch_dashed_line_divider" 
    /> 

을 설정하지만 분배기 마진이 왼쪽 바로 원하는 listview. 도형에 채우기를 설정하려고했지만 listview은 채우기를 무시합니다.

<padding 
     android:bottom="15dp" 
     android:left="15dp" 
     android:right="15dp" 
     android:top="15dp" /> 

listview 분할에 여백을 설정하는 가능성이 있는가 - 어댑터의의 getView()를 제외하고?

+0

최상의 솔루션 : http://stackoverflow.com/questions/14054364/how-to-assign-padding-to-listview-item-divider-line?lq=1 – ASP

답변

81

삽입 된이 .....

<?xml version="1.0" encoding="UTF-8"?> 
<inset xmlns:android="http://schemas.android.com/apk/res/android" 
    android:insetLeft="15dp" 
    android:insetRight="15dp" > 

    <shape 
     android:shape="line" > 
     <stroke 
      android:dashGap="1dp" 
      android:dashWidth="1.5dp" 
      android:width="1dp" 
      android:color="#FF404040" /> 

      <size android:height="3dp" /> 

    </shape> 

</inset> 
+0

쉽게 가장 좋은 대답은 여기에 있습니다. 이것은 인 세트 XML 구조가되는 것입니다. – Adam

+7

줄을 원한다면 <솔리드 android : color = "@ color/list_divider"/> 을 사용하고 ListView에 속성 "android : dividerHeight"를 설정하십시오 – Maragues

3
u've 마진

<gradient android:startColor="#000000" android:centerColor="#ffffff" 
    android:endColor="#000000" /> 
에게 주어진처럼 U 그것은 나타납니다 ... u'll 화이트를 얻을 중앙에, 그것은 시작과 검은 색으로 끝이 샘플로 시험 인쇄를 해보십시오 .. 대신 스트로크의 오른쪽 및 왼쪽 마진을 얻을 그라데이션을 사용할 수 있습니다

+0

이것은 좋은 해결책입니다. ,하지만 나는 디바이더에서 파선에 대한 스트로크가 필요하므로 그라디언트를 사용할 수 없습니다. – Fabian

1

나는 그것을 믿지 않는이 가능합니다 : 각 목록 항목의 하단에 자신의 당김을 추가 및 제거 할 경우의 ListView 당신이 폴더 입술을 만들기 : 당신이 원하는 그러나

그것을 사용자 정의 할 수 있습니다 산기/만/drawable 및 새 xml 만들기 :

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

    <solid android:color="#666666"></solid> 

</shape> 

.. 그 드로어 블을 당신의 아이템으로 사용하십시오.

아니면 정말 신속하고 더러운 방법은 가짜 사용자 정의 ListView를 분할에 목록 항목의 맨 아래에 배경 색깔 얇은있는 LinearLayout (또는 다른 레이아웃)을 만들 OFC 것입니다 ..

하지 적절한 sollution 단지 일부 픽스 잇 아이디어)

+0

이것이 내 생각이었습니다. 그것을 어댑터에 직접 부착하십시오. 그러나이 어댑터가 아닌지 나는 알 수 없습니다. – Fabian

+0

그것을보십시오;) 또는 자신의 사용자 지정 ListView, 비록 내가 그 문제의 가치가있을 것입니다 의심. – DecodeGnome

5

다음과 같은 아이디어를 사용할 수 있습니다 : 그것은 나를 위해 작동

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="@color/table_background"/> 
    </shape> 
</item> 
<item android:left="2dp" android:right="2dp"> 
    ... your shape here ... 
</item> </layer-list> 

. 희망이 도움이 될 것입니다.

16

사용 '삽입'을 갈 수있는 방법입니다

(list_divider.xml)

<?xml version="1.0" encoding="UTF-8"?> 
<inset xmlns:android="http://schemas.android.com/apk/res/android" 
    android:insetLeft="50dp" 
    android:insetRight="50dp" > 

<shape> 
    <solid android:color="@color/orange" /> 
    <corners android:radius="2.0dip" /> 
</shape> 

</inset> 

하고 목록보기는 다음과 같이 추가에 ...

<ListView 
    android:dividerHeight="2dp" 
    android:divider="@drawable/list_divider" 
    ... 
/> 

다음과 같은 값을 설정할 수 있습니다. 원하는 ...

+1

''요소를'shape'에 직접 배치하여 모든리스트 뷰의 높이를 반복하지 않도록 할 수 있습니다. – Natix