2012-07-12 20 views
3

我得到了SO幾個問題關於這一主題列表視圖項目,但所有這些之間的距離是列表視圖項和幾乎所有的答案之間有關距離建議使用透明分頻器作爲解決方案。有分頻器

但在我的情況下,我已經有兩個列表項目之間的分隔,所以我怎麼能申請一些邊距/填充/兩個列表項目之間的距離?

任何幫助表示讚賞。

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listMainPlans" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:divider="@drawable/list_divide" 
     android:dividerHeight="2dp" > 
    </ListView> 

</LinearLayout> 
+0

請發佈xml佈局代碼。 – 2012-07-12 11:52:59

+1

取決於您準確要達到的佈局。您可以創建/充氣自定義列表項並在XML中添加所需的填充/邊距。 – DroidBender 2012-07-12 11:53:39

+0

這個XML看起來很好。關於**邊距/填充/距離**,如果您爲ListView準備了自定義適配器,則可以在行xml佈局中留下填充/邊距。 – 2012-07-12 11:56:17

回答

4

基於this tutorial,您可以添加paddinglistview_item_row.xml

使用適配器的時候可以(在本教程WeatherAdapter.java)膨脹這個XML的每個元素在你的ListView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp"> // <----- 

    <ImageView /> 

    <TextView /> 

</LinearLayout> 
+0

它通過設置填充頂部和底部到父級相對佈局的工作。 – GAMA 2012-07-12 12:09:20

+0

還有另一種方法:我可以添加一個固定高度的虛擬文本視圖。 – GAMA 2012-07-12 12:09:47

+0

添加一個空的'TextView'來建立佈局不是最好的工作方式:) – DroidBender 2012-07-12 12:11:59

1

給靜態高度到相對佈局,如:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/ic_innerbg"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/item_background" 
     android:minHeight="40dp"> 

    <TextView 
     android:id="@+id/txtTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="16dp" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="10dp" 
     android:textColor="@color/blue" 
     android:layout_marginRight="45dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" 
     android:textStyle="bold"/> 



    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerInParent="true" 
     android:layout_marginRight="10dp"/> 

    </RelativeLayout> 

</RelativeLayout> 

您將獲得每行產品之間的距離