你将无法实现你想要的那么简单.
第一步:将分隔线设置为透明,并使高度更大:
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:dividerHeight="8dp"/>
第二步:为了实现’小线’效果,可以添加自定义drawable作为列表视图项背景,比如列表视图项被定义为’list_item.xml’:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_item_selector"
android:orientation="vertical" >
当然,那个项目可以是你喜欢的任何东西,我的是:
android:shape="rectangle">
android:shape="rectangle">
但那会禁用“Holo Selector”效果,无论何时单击或突出显示列表视图中的项目,都会有一个Holo Blue颜色,这就是为什么如果你注意到列表项背景我们没有使用一个图层列表drawable,我们使用了一个名为’list_item_selector’的选择器.
这是选择器,它在未按下时使用可绘制的图层列表,并在按下时使用全蓝色:
android:state_pressed="false"
android:drawable="@drawable/list_item_bg2"
/>
android:drawable="@color/holo_blue"
/>
编辑评论
绝对可以,您可以为列表视图项定义设置高度,但是,建议设置最小高度,而不是永远不会更改的预定义高度.
说这是我的列表项布局:
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/grid_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
android:id="@+id/grid_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_toRightOf="@+id/grid_image"
android:minHeight="48dp"
android:padding="8dp"
android:textIsSelectable="false" />
所有需要的都是,
第一步:根据您的喜好,在values /文件夹中包含的dimens.xml文件中定义最小高度或最大高度.为什么?因为高度应该根据布局明确改变,并且您可以为每个设备密度定义不同的dimens.xml.
在dimens.xml中,说:
48dp
96dp
64dp
然后使用列出项目布局的父LinearLayout的任何值.
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_min_height" >
这就是那个主题,现在以文本为中心,它甚至更简单:
>如果您使用的是TextView并将其包装到RelativeLayout中,请使用:android:layout_centerVertical =“true”
>如果您使用的是LinearLayout,请使用:android:layout_gravity =“center_vertical”
并将其与:结合使用:注意这仅适用于未将高度设置为wrap_content的情况,否则无关紧要.
android:gravity="center_vertical"
希望有所帮助.