2012-08-27 58 views
18

我的理解是,为列表视图定义的分隔线应该出现在列表的顶部和底部,即在第一个项目的上方和最后一个项目的下方。顶部和底部的分隔线不显示在Android列表视图

因为他们不会出现在我的列表视图某些原因:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/background"> 

<ImageView 
    android:id="@+id/home" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="3dp" 
    android:paddingTop="3dp" 
    android:paddingBottom="3dp" 
    android:src="@drawable/homeicon"/> 

<TextView 
    android:id="@+id/titleBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Page Title" 
    android:layout_marginLeft="10dp" 
    android:paddingTop="3dp" 
    android:textSize="18sp" 
    android:textStyle="bold" 
    android:typeface="serif" 
    android:textColor="#FFFFFF" 
    android:layout_centerHorizontal="true"/> 

<ImageView 
    android:id="@+id/back" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingRight="8dp" 
    android:paddingTop="8dp" 
    android:src="@drawable/backicon" 
    android:layout_alignParentRight="true"/> 


<ImageView 
    android:id="@+id/separator1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/home" 
    android:scaleType="fitXY" 
    android:src="@drawable/separatorimg" /> 


<ListView 
    android:id="@android:id/android:list" 
    android:layout_below="@+id/separator1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000" 
    android:divider="@drawable/separatorimg"> 
</ListView> 

</RelativeLayout> 

设置机器人:footerDividersEnabled为true(这是在围绕这个问题其他问题给出的答案)不会改变任何东西。此外,我没有禁用的项目,除非有某种默认页脚会被禁用。

任何想法?

编辑:当我滚动过第一个/最后一个项目,然后消失时,似乎顶部和底部的分隔线出现一瞬间。它看起来好像接口将继续,只是在后来才意识到这是最后一项,然后禁用分频器。

回答

0

我想你必须使用列表视图下方的视图来设置页脚。我有同样的问题,这就是我能得到作为一个解决方案:

Show divider after the last item in the list

+0

感谢您的回答,不幸的是,这并不适合我。首先,该视图仅显示其下面是否有其他元素(不知道为什么),其次,即使显示,它仍保持始终可见在屏幕的底部。我试图达到的效果是,分频器只出现在列表的末尾,就像它随着它滚动一样。 – InterRaptor

+0

你尝试过吗?因为它按照你想要的方式工作 –

+0

我试了一下,在接受的答案中复制了代码(替换listview id)在listview下方。即使有许多列表项目仍然需要滚动,我仍然会在屏幕底部出现一条绿线。 – InterRaptor

0

请看以下修改后的代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/background" > 

<LinearLayout 
    android:id="@+id/llAppBar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:orientation="horizontal" 
    android:weightSum="10" > 

    <ImageView 
     android:id="@+id/home" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:paddingBottom="3dp" 
     android:paddingLeft="3dp" 
     android:paddingTop="3dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/homeicon" /> 

    <TextView 
     android:id="@+id/titleBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_weight="6" 
     android:paddingTop="3dp" 
     android:text="Page Title" 
     android:textColor="#FFFFFF" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <ImageView 
     android:id="@+id/back" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:paddingRight="8dp" 
     android:paddingTop="8dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/backicon" /> 
</LinearLayout> 

<ImageView 
    android:id="@+id/separator1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/llAppBar" 
    android:scaleType="fitXY" 
    android:src="@drawable/separatorimg" /> 

<ListView 
    android:id="@android:id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/separator1" 
    android:cacheColorHint="#00000000" 
    android:divider="@drawable/separatorimg" > 
</ListView> 

</RelativeLayout> 
+0

我想你已经添加了LinearLayout以便能够使用重量。好主意,但没有运气,仍然没有出现顶部或底部的分隔线。 – InterRaptor

4

我有同样的问题。下面是我如何解决它:

<ListView 
    android:id="@+id/my_list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:divider="@color/transparent" 
    android:dividerHeight="@dimen/padding_default" 
    android:footerDividersEnabled="false" 
    android:headerDividersEnabled="false" > 
</ListView> 

然后,在onCreate()方法,我有:

View v = new View(this); 
v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1)); 
mList.addFooterView(v); 
28

我解决了使用帮助,从以下链接这个问题:Divider disappears from last item in listview if footerview added

我确实添加了

android:footerDividersEnabled="true" 

属性为XML中的ListView。然后编程,我说那是可选择空页脚视图使用

listView.addFooterView(new View(context), null, true); 

我没有尝试的头,但我希望它的工作方式相同。

+0

对我来说,只有当页脚被标记为可选时,分隔符才会出现,即对'addFooterView'的最后一个参数是'true'。将其设置为“false”不会显示分隔符。 – nickgrim

-2

我有同样的问题,并设置填充和背景颜色解决它。

<ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/gray_background" 
    android:paddingTop="1dp" 
    android:paddingBottom="1dp"   
/> 

在这里,背景颜色应该与带有列表视图的分隔线的颜色相同。

+0

当您滚动时,此解决方案不会消失 – Hrk

相关问题