【问题标题】:List View not displaying divider for 1st item with Text View on top列表视图不显示第一个项目的分隔线,顶部有文本视图
【发布时间】:2013-07-08 06:17:28
【问题描述】:

我在列表视图顶部有一个文本视图,但列表未显示标题分隔线,但如果我删除文本视图并仅保留列表视图,则显示标题分隔线。

我也试过这个:HeaderDividerEnabled : true 但不工作。

 <TextView 
            android:id="@+id/tv"
            android:visibility="gone"
            android:layout_below="@+id/header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:gravity="center_horizontal"
            android:textColor="#000000"
            android:textSize="@dimen/text_size"/>
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tv"
            android:layout_marginTop="2dp"
            android:cacheColorHint="#00000000"
            android:overScrollMode="never"
            android:divider="@color/black"
            android:dividerHeight="0.8dp"
            android:listSelector="@drawable/selector">
        </ListView>

【问题讨论】:

  • 尝试添加 android:dividerHeight="1px"... 即 px 而不是 dp
  • 使用相对布局的任何具体原因..
  • @CRUSADER 好的,我会试试的
  • @KingCobraa 是的,我还有一些视图要显示,这些视图将放置在其他视图的左右两侧
  • 能否请您发布您的设计..

标签: android android-listview header textview


【解决方案1】:

这不是 android:headerDividersEnabled 应该做的。这意味着如果您要添加列表标题,则该标题是否需要用分隔符分隔。

这是一个工作示例:stackoverflow.com/a/8819402/915756

希望对你有帮助

【讨论】:

    【解决方案2】:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Hi Goofy"
            android:textSize="30sp" />
    
    
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:cacheColorHint="#00000000"
            android:background="@drawable/border"
            android:divider="@android:color/background_dark"
            android:dividerHeight="0.8dp"
            android:entries="@array/hh"
            android:footerDividersEnabled="true"
            android:headerDividersEnabled="true"
            android:overScrollMode="never" >
        </ListView>
    
    </LinearLayout>
    

    /// 边框

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
       <!-- use this for transparent -->
       <!-- <solid android:color="#00000000" /> -->
       <!-- use this for a background colour -->
       <solid android:color="#FFF" />
       <stroke android:width="2dip" android:color="#FF0000" />
    </shape>
    

    【讨论】:

    • 在列表视图中只需删除条目并放入您的数据。
    • 好的,我会试试这个,但我们可以在不添加视图的情况下做到吗?
    • 只需为列表视图设置边框,请参阅我的更新...我设置了红色,您可以使用与分隔线相同的颜色
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-19
    相关资源
    最近更新 更多