简体   繁体   中英

ListView Background

EDITED:

I have problem with setting background image for my ListView. In graphical view of activity it's looking good, but on the phone, there is no background at all. It's my activity .xml code :

<?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"  
android:gravity="bottom|fill_vertical" 
android:background="@drawable/background">

   <ListView
      android:id="@+id/listPlan"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:divider="@null"
      android:cacheColorHint="#00000000" 
      android:listSelector="@android:color/transparent" 
      android:scrollingCache="false" 
      android:dividerHeight="5dp" >

   </ListView>

</LinearLayout>

It's one of activity in GroupActivity if it means something for my problem. I've tried everything - giving android:background for ListView , for LinearLayout , even for parent activity ( GroupActivity ), changing android:layout values for every item I could, nothing helps.

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/text"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" 
     android:textSize="20sp"
     android:padding="15dp" 
     android:scrollHorizontally="true" >
</TextView>

This is how my Single List Item looks like, maybe there is some mistakes?

I saw difference only when i edited my <TextView> and giv it android:background , every one other try to change background og this listview was unspotted - for example I've changed android:cacheColorHint="#00000000" to android:cacheColorHint="#FFFFFFFF" - nothing happened.

I will try one more time - after changing layout from Linear to Relative nothing happend, but this (thanks to @Sam ) give me to think. Maybe I have to add something in my AndroidManifest.xml? If code works properly, maybe this parent GroupActivity is have a bigger influence on ListView , then i thought. Unfortunately I can't put images, but u can see two states of this ListView here: https://www.dropbox.com/sh/y5dgibei5uq9kv9/afeIvgW18g

Wow, the problem is a little weird, because when I tried to set android:textColor for my ListView nothing changed! This is my styles.xml:

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>

Thanks for every respond.

LAST EDIT!

Okay, problem solved, because nothing helps me, I've tried another way and just set my ListView background in code :

if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        list.setBackgroundResource(R.drawable.background);
    else list.setBackgroundResource(R.drawable.background_landscape);

Now everything is working well! Thank You guys for every respond. Peace out.

This solved my problem :-

android:cacheColorHint="#0000"

add it to your listview:-

<ListView
android:id="@+id/listPlan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cacheColorHint="#0000">

"#0000" -> transparent color code

Just Add this in to listview.xml file

android:cacheColorHint="#00000000"

Or you can use Expandable Listview
Edited :

Use Relative layout instead of linear layout and please check../

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/ic_launcher" 
        android:cacheColorHint="#00000000">
    </ListView>

</RelativeLayout>

Try this :

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
     android:layout_height="match_parent"   
     android:orientation="vertical" >


      <ListView
       android:id="@+id/contract_diary_list"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"        
       android:fadingEdge="none"        
       android:divider="@null"
       android:scrollingCache="false"
      android:listSelector="@android:color/transparent"
     >
     </ListView> 

   </LinearLayout>

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