我正在寻找一些ListView
样式技术,我找到了这个Post-How to make card List,我希望ListItems
就像这样:
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>
但是我得到了这个:
无法在margin
Items
ListView
之间得到margin
,如上图所示,我应该设置{{1}}。
答案 0 :(得分:1)
您可以尝试使用listview行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>
和CardOuterStyle
<style name="CardOuterStyle">
<item name="android:paddingLeft">5dp</item>
<item name="android:paddingRight">5dp</item>
<item name="android:paddingTop">5dp</item>
</style>
答案 1 :(得分:0)
您应将dividerHeight
的{{1}}设置为:
ListView
或者,您也可以在相对布局中给出填充:
<ListView android:id="@+id/MyListView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:divider="@android:color/transparent"
android:dividerHeight="@dimen/ten"/>