android问题,求助
自定义了一个view,里面主要是对一张图片的旋转处理。,然后在activity里,用handler和timer去实现图片自动旋转。。当我手势向上滑动时,图片开始旋转,但现在旋转不了,,自定义的view。。
public class MyView extends View {
private Context context ;
private Bitmap showBmp ;
private Matrix matrix ;
private Camera camera ;
public int deltaX ;
private int centerX , centerY ;
public MyView(Context context){
super(context);
this.context = context ;
initData();
}
//自定义view组件
public MyView(Context context,AttributeSet att) {
super(context,att);
this.context = context ;
initData();
}
private void initData(){
showBmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.coinface);
centerX = showBmp.getWidth()/2 ;
centerY = showBmp.getHeight()/2 ;
matrix = new Matrix();
camera = new Camera();
// timer=new Timer();
}
//布局位置
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
}
//重新绘画
protected void onDraw(Canvas canvas) {
camera.save();
//绕X轴旋转
camera.rotateX(deltaX);
camera.getMatrix(matrix);
camera.restore();
//translate平移,pre前
matrix.preTranslate(-this.centerX, -this.centerY);
//post是后乘,当前的矩阵乘以参数给出的矩阵
matrix.postTranslate(this.centerX, this.centerY);
canvas.drawBitmap(showBmp, matrix, null);
}
}
activity里:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
//MIN_DISTANCE滑动的最短距离
if(e1.getY()-e2.getY()>MIN_DISTANCE){
Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
switch(msg.what){
case 1:
myView.deltaX+=95.0f;
break;
}
myView.invalidate();
}
};
//定时器
timer.schedule(new TimerTask() {
@Override
public void run() {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
}, 0,1);
Toast.makeText(this, "滑动了", Toast.LENGTH_LONG).show();
return true;
}else{
return false;
}
}
是不是handler写错了,滑动了没更新UI。。。toast显示滑动了。。
补充:移动开发 , Android