Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – ListView项目顶部和底部的ListView分隔符大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Android Listview,并且我想在listview项目的两侧使用1px分隔符意味着在两种不同颜色的顶部和底部.但问题是我没有登录显示底部的分隔符.我试过android:layouT_Below,但它显示为无效.

这是Listview代码

<ListView
        android:id="@+id/myphnview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layouT_Below="@drawable/dividerheight"
        android:BACkground="#E9EAEC"
        android:clickable="true"
        android:divider="@drawable/dividerheight" >
    </ListView>

这是我用于顶部边框的xml文件. dividerheight.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://scheR_614_11845@as.android.com/apk/res/android" >

    <item>
        <shape android:shape="line" >
            <stroke android:color="#c6c7c9" />

            <size android:height="1px" />
        </shape>
    </item>


</layer-list>

这是我的行的布局

<LinearLayout xmlns:android="http://scheR_614_11845@as.android.com/apk/res/android"
    android:id="@+id/rowlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:BACkground="#E9EAEC"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2" >

        <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp" 
            android:BACkground="@drawable/ic_launcher"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_weight="1" >

        <TextView
            android:id="@+id/file_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_margin="5dp"
            android:text="Hello Android "
            android:textColor="@android:color/black"
            android:textSize="20dp" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" >

        <ImageView
            android:id="@+id/share_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:BACkground="@drawable/ic_launcher"/>
    </LinearLayout>



</LinearLayout>

解决方法

有几种方法可以实现这一目标.一种简单的方法是在列表中完全隐藏分隔符(将分隔符宽度设置为0或将分隔符设置为空),并让每个列表项包含顶部的一行和底部的一行.虑一下这个xml:
<RelativeLayout xmlns:android="http://scheR_614_11845@as.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="60dp">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentTop="true"
        android:BACkground="@android:color/white" />

    <LinearLayout ...>
        <!-- this is your current list item LinearLayout -->
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true"
        android:BACkground="@android:color/black" />

</RelativeLayout>

由于您已经在使用自定义适配器,因此只需在适配器的getView方法中使用上面的XML作为列表项布局.这将生成60dp的列表项,顶部带有白线,底部带有黑线.

大佬总结

以上是大佬教程为你收集整理的android – ListView项目顶部和底部的ListView分隔符全部内容,希望文章能够帮你解决android – ListView项目顶部和底部的ListView分隔符所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。