使用我的 GridView 实现 Palette 时,我无法滚动。
基本上,情况如下: GridView 中的每个项目都有一个标题栏和一个加载的图像。使用调色板,标题栏应该更改为调色板提取的提取颜色。
但发生的情况是,每次我向下滚动 Grid View,然后向上滚动时,定位都会随着栏背景颜色而变化。
这是一个例子:
然后当我向下滚动并再次向上滚动时:
另外,颜色似乎也不对吗?出于某种原因,它看起来只是选择了最后加载的颜色,有时甚至根本没有加载,正如您在查看条形图时看到的那样。
我在我的专辑适配器中这样做,这是代码,希望有人可以指导我正确的方向。
public class AlbumAdapterNew extends ArrayAdapter<String> {
ArrayList<String> names;
Activity context;
ArrayList<String> coverPaths;
String coverPath;
Drawable img;
Bitmap bitmap;
ViewHolder mViewHolder = null;
ImageLoader imageLoader = ImageLoader.getInstance();
private RelativeLayout background;
static class ViewHolder {
private TextView text;
private ImageView image;
}
public AlbumAdapterNew(Activity context, ArrayList<String> names,
ArrayList<String> coverPaths) {
super(context, R.layout.albums_row, names);
this.names = names;
this.context = context;
this.coverPaths = coverPaths;
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.displayer(new FadeInBitmapDisplayer(500))
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context)
.defaultDisplayImageOptions(defaultOptions)
.build();
ImageLoader.getInstance().init(config); // Do it on Application start
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
mViewHolder = new ViewHolder();
LayoutInflater vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.albums_row, parent, false);
mViewHolder.text = (TextView) convertView
.findViewById(R.id.albumTextView);
mViewHolder.image = (ImageView) convertView
.findViewById(R.id.album_photo);
background = (RelativeLayout) convertView
.findViewById(R.id.containerText);
convertView.setTag(mViewHolder);
}
else {
mViewHolder = (ViewHolder) convertView.getTag();
}
mViewHolder.text.setText(names.get(position));
if (coverPaths.get(position) != null && !coverPaths.isEmpty()) {
mViewHolder.image.setScaleType(ScaleType.CENTER_CROP);
Glide.with(context).load("file:///" + coverPaths.get(position))
.asBitmap()
.into(new BitmapImageViewTarget(mViewHolder.image) {
@Override
protected void setResource(Bitmap resource) {
// Do bitmap magic here
Palette.from(resource).generate(
new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
Palette.Swatch vibrantSwatch = palette
.getVibrantSwatch();
if (vibrantSwatch != null) {
background
.setBackgroundColor(vibrantSwatch
.getRgb());
}
}
});
super.setResource(resource);
}
});
} else {
mViewHolder.image.setScaleType(ScaleType.CENTER_INSIDE);
imageLoader.displayImage("drawable://" + R.drawable.music_record,
mViewHolder.image);
}
return convertView;
}
}