2014-03-01 84 views
0

卡列表我一直在尋找一些ListView,造型技巧,我發現這一個Post-How to make card List,我希望ListItems成爲像這樣:如何使機器人

Image of List list_item_background.xml是:

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

     <corners android:radius="2dp"/> 

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

    </shape> 
</item> 

<item android:bottom="2dp"> 
    <shape android:shape="rectangle" 
     android:dither="true"> 

     <corners android:radius="2dp" /> 

     <solid android:color="@android:color/white" /> 

     <padding android:bottom="8dp" 
      android:left="8dp" 
      android:right="8dp" 
      android:top="8dp" /> 
    </shape> 
</item> 

我已經實現了,在我的RowOfListView.xml,如:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/ten" 
     android:background="@drawable/list_item_background" > 
<ImageView 
    android:id="@+id/imageView_in_row" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignTop="@+id/row_member_name" 
    android:layout_marginBottom="@dimen/ten" 
    android:layout_marginLeft="@dimen/five" 
    android:background="@drawable/rectangle" 
    android:contentDescription="@string/image" 
    android:src="@drawable/member" /> 

<TextView 
    android:id="@+id/row_member_name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="@dimen/ten" 
    android:layout_marginRight="@dimen/ten" 
    android:layout_marginTop="@dimen/ten" 
    android:layout_toRightOf="@+id/imageView_in_row" 
    android:ellipsize="end" 
    android:text="Text" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 
. 
. 
. 
</RelativeLayout> 

但我發現了這樣一條:

Image

無法獲取margin如在現有的畫面,我應該在哪裏設置marginItems之間ListView

+1

你可以發佈我們的適配器代碼嗎? –

回答

1

你可以嘗試這樣的列表視圖行XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/outer" 
    style="@style/CardOuterStyle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/dialog_white" 
     android:orientation="vertical" > 
//your fields here 
</LinearLayout> 
</FrameLayout> 

and CardOuterStyle

<style name="CardOuterStyle"> 
     <item name="android:paddingLeft">5dp</item> 
     <item name="android:paddingRight">5dp</item> 
     <item name="android:paddingTop">5dp</item> 
    </style> 
0

你應該設置的ListView作爲dividerHeight

<ListView android:id="@+id/MyListView" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="@dimen/ten"/> 

或者,您也可以給填充在相對佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="@dimen/ten" 
    android:background="@drawable/list_item_background" 
    android:paddingTop="@dimen/five" 
    android:paddingBottom="@dimen/five" > 
+0

感謝您的「考慮」,但我仍然無法得到像那樣的結果.. –