我需要在自定义列表视图中制作一个列表视图,其中我只想在某个位置上有分隔符,而不是在每个列表项后面都有。请问有没有解决这个问题的方法?
我需要在自定义列表视图中制作一个列表视图,其中我只想在某个位置上有分隔符,而不是在每个列表项后面都有。请问有没有解决这个问题的方法?
您可以在列表适配器类中使用此XML文件,如下所示:
ItemsAdapter ItemsAdapter = new ItemsAdapter(EnterpriseFertilisersScreen.this,
R.layout.list, Constant.FERTILIZERMANAGERARRAY);
R.layout."下面的XML文件"并将用户作为进一步的白色颜色。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@color/list_bg" >
<TextView
android:id="@+id/post"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="7dp"
android:layout_toRightOf="@+id/bite_image"
android:gravity="center_vertical"
android:textColor="@android:color/white"
android:textSize="20sp" />
</RelativeLayout>
如果你已经使用了自定义的ListView来展示你的数据,而你需要根据条件在特定位置展示不同的xml视图,那么你需要在getView
方法中进行操作。
或者你可以查看这个例子,了解如何使用CursorAdapter
实现分割线效果。
你可以按照以下方式将其添加到getView方法中:
public View getView(int position, View convertView, ViewGroup parent) {
if(items.get(position).get("name").startsWith("-")){
View divider = mInflater.inflate(R.layout."yourlayout",null);
return divider; }
另外,您必须在想要添加分隔符的项目名称前加上“-”。
希望这有所帮助。