Paint deafalutPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
+ reflectionGap, paint);
return bitmapWithReflection;
}
}
2、加载图片的线程
class MyThread extends Thread{
int index;
public MyThread(int index) {
super();
this.index = index;
}
@Override
public void run() {
if (imageList.get(index).getIsNull().equals(ISTRUE)) { imageList.get(index).setImage(ImageManager.getRefImage(imageList.get(index)
.getPath()));
imageList.get(index).setIsNull(ISFALSE);
}
refreshAdapter();
}
}
3、gallery的滑动事件
private Gallery.OnItemSelectedListener itemSelected_listener = new Gallery.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
long arg3) {
toShowIndex = position;
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (showingIndex != toShowIndex) {
showingIndex = toShowIndex;
// 业务逻辑处理
if (toShowIndex < imageList.size()) {
addImage(toShowIndex);
}
}
}
};
Thread checkChange = new Thread() {
@Override
public void run() {
int myIndex = toShowIndex;
try {
sleep(TIME_OUT_DISPLAY);
if (myIndex == toShowIndex) {
handler.sendEmptyMessage(0);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
checkChange.start();
TextView gallery_total = (TextView) findViewById(R.id.gallery_total);
gallery_total.setText((toShowIndex + 1) + "/"+ imageList.size()); }
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
};
4、更新ImageAdapter
private void refreshAdapter() {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
adpter.notifyDataSetChanged();
}
});
}
5、从sd卡里获取图片后封装对象
public List<ImageMessage> getAllImageMessage() {
List<ImageMessage> imageList = new ArrayList<ImageMessage>();
getSD(Environment.getExternalStorageDirectory().toString()+ "/");
for (int i = 0; i < pathList.size(); i++) {
ImageMessage im = new ImageMessage();
im.setPath(pathList.get(i)[0]);
im.setName(pathList.get(i)[1]);
im.setIsNull(ISTRUE);
imageList.add(im);
}
return imageList;
}