简体   繁体   中英

android-listview problem with transparent cells

I want to make a listview with semi-transparent cells (some sort of blue with 25% opacity).

The listview is created correctly but, when i perform an scroll motion(I press and drag down or up) the list seems to activate some sort of selection mechanism witch applies a black and opaque background to the list.

Any Idea how I can get rid of this?

Below is the code and the two screens:

<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="@drawable/background">
<ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:background="@drawable/my_health_title">
</ImageView>
<ListView android:id="@+id/health" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</ListView>

<TextView android:id="@+id/health_title" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:textColor="#46727c"
    android:textSize="14sp" android:textStyle="bold"
    android:layout_marginTop="20dp" android:layout_marginLeft="30px"
    android:text="Blood presure Profile">
</TextView>

<LinearLayout android:id="@+id/health_gauge"
    android:layout_width="250dp" android:layout_height="35dp"
    android:layout_centerVertical="true" android:layout_marginLeft="20dp">
</LinearLayout>

<TextView android:id="@+id/health_description"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:textColor="#46727c" android:textSize="12sp" android:textStyle="normal"
    android:layout_marginTop="150px" android:layout_marginLeft="30px"
    android:text="Looks Goood">
</TextView>

<ImageView android:id="@+id/health_details"
    android:background="@drawable/home_arrow_icon_margin"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_alignParentRight="true" android:layout_centerVertical="true">
</ImageView>

normal list

selected efect

I was having a nightmare with a similar problem. But I was adding the ListView dynamically, and

android:cacheColorHint="#00000000"

didn't work in this case. The solution:

Don't add ListView dynamically, cacheColorHint will not work

Hope this helps someone!

Just set the android:cacheColorHint to #00000000 on your ListView.

Notice that the color code is an 8 digit code ( #AARRGGBB ), which means that the first two digits represents the alpha of the color. (If you set it to a 6 digit, #000000 it won't help, because it will be still opaque. For more info on color codes click here ).

Your list view should look like this:

<ListView android:id="@+id/health" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:cacheColorHint="#00000000">
</ListView>

More details and explanation can be found here .

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