ListView的FadingEdge颜色是否可以更改?

4

我希望ListView看起来像从周围淡出。默认情况下,它会设置为与您的ListView颜色相同的颜色。我可以调整FadingEdge的方向和大小,但无法更改颜色。这可能吗?

3个回答

14

你需要创建一个继承ListView的新类。

package com.mypackage;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class ColorFadeListView extends ListView
{
  // fade to green by default
  private static int mFadeColor = 0xFF00FF00;
  public ColorFadeListView(Context context, AttributeSet attrs)
  {
    this(context, attrs,0);
  }
  public ColorFadeListView(Context context, AttributeSet attrs, int defStyle)
  {
    super(context,attrs,defStyle);      
    setFadingEdgeLength(30);
    setVerticalFadingEdgeEnabled(true);
  }
  @Override
  public int getSolidColor()
  {
    return mFadeColor;
  }
  public void setFadeColor( int fadeColor )
  {
    mFadeColor = fadeColor;
  }
  public int getFadeColor()
  {
    return mFadeColor;
  }
}

您可以将此列表视图与普通的 ListView 完全相同(尽管您必须正确地进行转换以使用 fadeColor 访问器方法)。在您的 XML 中,不要定义一个对象为<ListView android:properties.../>,而是定义为<com.mypackage.ColorFadeListView android:properties.../>


有没有办法在蜂巢上实现ActionBar的渐隐边缘? - draksia
1
这在我的摩托罗拉 Razer(Android 2.3.5)上不起作用。我得到了大小为30的淡出区域,但它们是黑色的。在2.3模拟器上和带有Android 2.3.5的HTC Desire S上工作。 - Jarrod Smith

5
当然可以!
setCacheColorHint(Color.WHITE);

谢谢,这确实做到了我想要的,但是它在滚动时也设置了背景颜色。有没有办法将这两个分开? - NotACleverMan
2
为您的单元格设置背景颜色。 - William Remacle
给你的listView设置与单元格相同的背景。显然,如果使用图像作为背景,则无法实现(请参见下面的解决方案)。 - bernstein

0
你可以尝试这个(我知道这是一个hack):
int glowDrawableId = context.getResources().getIdentifier("overscroll_glow", "drawable", "android");
Drawable androidGlow = context.getResources().getDrawable(glowDrawableId);
androidGlow.setColorFilter(brandColor, PorterDuff.Mode.MULTIPLY);

我利用发光效果实际上是一个共享的可绘制对象,并在其上应用了滤镜:http://evendanan.net/android/branding/2013/12/09/branding-edge-effect/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接