0
我想要使用水平滚动视图来实现此设计。 我已经用轮视图库 https://github.com/chemalarrea/Android-wheel
的帮助下,水平滚动视图这样做,但我没有得到有关如何填写这张图像的颜色,而不会干扰使用的setBackground方法的ImageView图像的方形区域的任何想法。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="15dp">
<kankan.wheel.widget.WheelView
android:id="@+id/slotwheel_look_color"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
适配器
private class SlotMachineAdapter_Look extends AbstractWheelAdapter {
// Image size
final int IMAGE_WIDTH = 100;
final int IMAGE_HEIGHT = 100;
private LayoutInflater mInflater;
private LinearLayout mLn_parant;
private ImageView mImg_condition;
// Layout inflater
private Context context;
// Slot machine symbols
private final int items[] = new int[]{
R.drawable.image_1,
R.drawable.image_2,
R.drawable.image_3,
R.drawable.image_4,
R.drawable.image_5,
R.drawable.image_6,
R.drawable.image_7,
R.drawable.image_8,
R.drawable.image_9
};
// Cached images
private List<SoftReference<Bitmap>> images;
/**
* Constructor
*/
public SlotMachineAdapter_Look(Context context) {
this.context = context;
mInflater = LayoutInflater.from(context);
images = new ArrayList<SoftReference<Bitmap>>(items.length);
for (int id : items) {
images.add(new SoftReference<Bitmap>(loadImage(id)));
}
}
/**
* Loads image from resources
*/
private Bitmap loadImage(int id) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), id);
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, IMAGE_WIDTH, IMAGE_HEIGHT, true);
bitmap.recycle();
return scaled;
}
@Override
public int getItemsCount() {
return items.length;
}
// Layout params for image view
LayoutParams params = new LayoutParams(IMAGE_WIDTH, IMAGE_HEIGHT);
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
ImageView img;
if (cachedView != null) {
img = (ImageView) cachedView;
} else {
img = new ImageView(context);
}
img.setLayoutParams(params);
SoftReference<Bitmap> bitmapRef = images.get(index);
Bitmap bitmap = bitmapRef.get();
if (bitmap == null) {
bitmap = loadImage(items[index]);
images.set(index, new SoftReference<Bitmap>(bitmap));
}
BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap);
img.setBackground(ob);
img.setImageBitmap(bitmap);
img.setColorFilter(Color.YELLOW);
return img;
//返回图; }
}
请帮我解决这个问题。
在此先感谢
你尝试使用'setColorFilter'或'setTint'为你的形象?这不会干扰图像的背景颜色。 – Mithun
是的setColorFilter正在工作,但它没有给出像这个屏幕截图的效果。setTint不能直接使用。 – KDOSHI
通过“效果像截图”你的意思是黑暗的地区和更轻的区域? – Mithun