简体   繁体   English

透明单元格的android-listview问题

[英]android-listview problem with transparent cells

I want to make a listview with semi-transparent cells (some sort of blue with 25% opacity). 我想用半透明的单元格(某种不透明度为25%的蓝色)制作一个listview。

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. listview是正确创建的,但是,当我执行滚动动作(我按住并向下或向上拖动)时,列表似乎激活了某种选择机制,将黑色和不透明的背景应用于列表。

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 但是我是动态添加ListView的,并且

android:cacheColorHint="#00000000"

didn't work in this case. 在这种情况下不起作用。 The solution: 解决方案:

Don't add ListView dynamically, cacheColorHint will not work 不要动态添加ListView,cacheColorHint将不起作用

Hope this helps someone! 希望这对某人有帮助!

Just set the android:cacheColorHint to #00000000 on your ListView. 只需在您的ListView 上将android:cacheColorHint设置为#00000000即可

Notice that the color code is an 8 digit code ( #AARRGGBB ), which means that the first two digits represents the alpha of the color. 请注意,颜色代码是8位数字代码( #AARRGGBB ),这意味着前两位数字代表颜色的alpha。 (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 ). (如果将其设置为6位数字,则#000000将无济于事,因为它仍然是不透明的。有关颜色代码的更多信息,请单击此处 )。

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 . 这里可以找到更多的细节和解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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