简体   繁体   中英

Android: ListView divider is transparent

Hey i have a listview filled with "custom" TextViews (just added a mehtod for convenience)

mRootView = inflater.inflate(R.layout.fragment_session_list, container, false);
mLV = (ListView) mRootView.findViewById(R.id.session_list);
mLV.setAdapter(SessionManager.getInstance(getActivity().getApplicationContext()));
mLV.setDivider(new ColorDrawable(Color.RED));
mLV.setDividerHeight(20);
mLV.setBackground(new ColorDrawable(Color.YELLOW));

The ListView is a Fragment of a ViewPager and the only thing shown at screen

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/session_list"
    style="@style/main.list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:smoothScrollbar="true">
</ListView>

The style for completion

<style name="main">
</style>

<style name="main.list">
    <item name="android:divider">#f00</item>
    <item name="android:dividerHeight">4px</item>
</style>

<style name="main.list.item">
    <item name="android:textColor">#f00</item>
    <item name="android:textSize">32dp</item>
    <item name="android:layout_height">48dp</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:background">#0ff</item>
</style>

The divider is not shonw. Instead the yellow background is visible. Any ideas?

EDIT: if I pull up the listview fast enough the top is red. (The "overshoot" part of the scrolling)

If you are changing the colour/drawable, you have to set/reset the height of the divider too. i have tried it out with

<ListView
    android:id="@+id/listViewInstituate"
    android:layout_width="fill_parent"
    android:layout_height="313dp"                        
    android:choiceMode="singleChoice"
    android:dividerHeight="1.9dp"        
    android:divider="@android:color/holo_red_light"

    >

</ListView>

and it works fine.

but this needs api level 14,

android:divider="@android:color/holo_red_light" 

so you can use

android:divider="#FFCC00"

i checked both. Thank you

in your code mLV.setDivider(new ColorDrawable(Color.RED)); and <item name="android:divider">#f00</item> make me confused

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM