2011-01-14 12 views
16

Mam ListView w moim układzie.Odległość między pozycjami w widoku listy

<ListView 
     android:id="@+id/list_infoitems" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 

Każda lista układ pozycja wygląda następująco:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@drawable/selector_custombutton" 
    android:padding="10dp" 
    android:layout_gravity="center"> 
    <TextView 
     android:id="@+id/text_history_station_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical|left" 
     android:textColor="@color/rnv_blue_540c"/> 
    <TextView 
     android:id="@+id/text_history_line_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical|left" 
     android:textColor="@color/rnv_blue_540c"/>  
</LinearLayout> 

chcę mieć dystans między wszystkich pozycji. Do tego grałem z Androidem: właściwość margin, ale bez powodzenia.

Czy ktoś wie, jak zmienić odległość między przedmiotami w widoku listy.

Dziękuję

Mur

+0

Odległość między rzędami? lub między każdym elementem, który pojawia się w wierszu? –

+0

między każdym wierszem = pozycja listy – Tima

Odpowiedz

29

Zawsze można ustawić właściwość dividerHeight. Android Docs

<ListView 
    android:id="@+id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:dividerHeight="5dp" 
/> 

Jeśli to nie to, co chcesz zrobić, to w elemencie listview można owinąć LinearLayout w RelativeLayout i dodać margines do LinearLayout

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="5dp" 
    /> 
</RelativeLayout> 
+0

Miałem taki sam pomysł jak twoja druga sugestia, ale twoja pierwsza pomaga mi i jest ładniej :) Dziękuję bardzo – Tima

+3

To zadziałało dla mnie, z tym wyjątkiem, że moja lista jest czarny, a dzielnik szary. Pamiętaj, aby zmienić dzielnik na ten sam kolor, co lista! android: divider = "# 00000" w moim przypadku. – NPike

+1

@NPike, lub spraw, aby rozdzielacz był przezroczysty z # 00000000 – softarn

0

Używaj wyściółkę lub marginesu lub samego ListView.

<ListView 
     android:id="@+id/list_infoitems" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5px" 
/> 
+0

nie, to nie pomaga – Tima

0

Aby encrease odległość między z nich przedmioty samo można użyć

android:dividerHeight="xxdpi" 

W

<ListView 
    android:id="@+id/list_infoitems" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:dividerHeight="xxdpi"/> 

Regarts, Marco

+0

czy widziałeś zaakceptowaną odpowiedź? – Tima

1

I odkryli, że dzielnik ListView ma problemy fragmentacji. Na urządzeniach 2.3 domyślnie zaimplementowana jest szara linia, która nie pojawia się na urządzeniach 4.x. Można to rozwiązać ręcznie, ustawiając ręcznie android:divider="some_value". Zajmuję się wszystkimi problemami z układem elementów ListView w samych układach elementów. Jest to brudna sztuczka, ale rozwiązuje problemy z wersją krzyżową. Zwróć uwagę na dodanie "ukrytego" widoku poniżej. To nie tylko rozwiązuje problem między elementami, ale zapewnia równe wypełnienie po ostatnim elemencie na liście.

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="5dp" /> 

    <View 
     android:below="@id/list" 
     android:layout_height="0dp" 
     android:layout_width="0dp" 
     android:margin_top="5dp" /> 
</RelativeLayout> 
Powiązane problemy