2010-03-30 43 views
16

Ive xác định nền màu trắng cho khá nhiều tất cả các widget và nó hoạt động, trừ khi di chuyển. Các thùng chứa nền đi màu đen trong khi di chuyển dẫn đến nhấp nháy gây phiền nhiễu.Hình nền ListView của tôi chuyển sang màu đen khi di chuyển - cách khắc phục?

+0

thể trùng lặp: http://stackoverflow.com/questions/2803028/gets-flickering-layouts-background-while-scrolling -the-listview-in-android – Praveen

Trả lời

54

Bạn sẽ cần sử dụng phương thức setCacheColorHint() của ListView.

Ví dụ: list.setCacheColorHint(yourBackColor);

Giải thích về vấn đề và giải pháp here

+18

Chỉ muốn thêm điều này trong trường hợp ai đó tìm thấy chuỗi này. Tôi đã sử dụng 'android: cacheColorHint = "# 00000000"' trên bố cục ListView để sửa. – Eno

4

ScrollingCache = "false" trong file * .xml của hoạt động của bạn cho đối tượng danh sách nên làm các trick, quá.

+9

Đó là một ý tưởng tồi tệ, nó làm cho việc di chuyển/ném danh sách chậm hơn rất nhiều. –

+1

Ồ, rất vui được biết! Đối với tôi, nó luôn hoạt động tốt. Tuy nhiên, tôi sẽ tránh điều này trong tương lai và sử dụng giải pháp setCacheColorHint() ... Cảm ơn! – ubuntudroid

0

Chỉ cần đặt nền trên đỉnh và không có điểm nhấn hoặc ảnh hưởng xấu khác đơn giản và không cần gợi ý hoặc bộ nhớ cache trong cách bố trí listview android:background="#000000" cho nền đen hoặc android:background="#FFFFFF" cho trắng

<?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:background="#000000" 
    android:orientation="vertical" > 
    <TextView 
     android:id="@+id/testscheck" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="12dp" 
     android:layout_marginBottom="12dp" 
     android:layout_weight="1" 
     android:layout_gravity="left|center" 
     android:gravity="left" 
     android:textColor="@color/ics" 
     android:textSize="14sp" 
     /> 
</LinearLayout> 
0

Tôi cố định vấn đề này bằng làm cho màu nền của các tế bào màu sắc giống như ListView, vì vậy:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="#FFFFFF"> 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#FFFFFF"> <---- Background color of ListView 
    </ListView> 
</LinearLayout> 

và sau đó hàng:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="8dip" 
    android:background="#FFFFFF"> <--- Background color of the cell 

    <LinearLayout 
     android:id="@+id/projects_cover_row_image_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:background="#444444" 
     android:layout_centerInParent="true" 
     android:layout_marginRight="8dip"> 

     <ImageView 
      android:id="@+id/projects_cover_row_image" 
      android:layout_width="50dip" 
      android:layout_height="50dip" 
      android:contentDescription="@string/projects_image_content"/> 
    </LinearLayout> 

    ... 

</RelativeLayout> 

rằng hoàn toàn đã thoát khỏi những vấn đề đối với tôi và có vẻ như giải pháp tốt nhất

Các vấn đề liên quan