我想在android上创建一个汽车仪表板。实际上我已经创建了这个应用程序。但这是基于动画,它工作得很好。现在我想添加两个按钮(上下)。当我点击手必须向上移动10度。再次点击按钮意味着手必须从当前位置向上移动10度,当我点击下来意味着它必须下降10度。我不能通过动画中的单个按钮来做到这一点。动画我想要创建更多按钮,每个按钮我想创建不同的动画。这非常复杂。请有人帮我这样做。我在这里添加我的代码
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class dash1 extends Activity {
ImageView img,img1;
Animation an,an1,an2,an3;Button bt,bt2,bt3,bt4;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView)findViewById(R.id.ImageView01);
final Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.minute);
final int w= bmp.getWidth();
final int h= bmp.getHeight();
final Matrix mat = new Matrix();
mat.postRotate(180);
Bitmap rtd = Bitmap.createBitmap(bmp, 0, 0, w, h, mat, true);
BitmapDrawable bmd = new BitmapDrawable(rtd);
img.setImageDrawable(bmd);
an = AnimationUtils.loadAnimation(this, R.anim.anim);
an1 = AnimationUtils.loadAnimation(this, R.anim.anim1);
an2 = AnimationUtils.loadAnimation(this, R.anim.anim2);
an3 = AnimationUtils.loadAnimation(this, R.anim.anim3);
bt = (Button)findViewById(R.id.Button01);
bt2 = (Button)findViewById(R.id.Button02);
bt3 = (Button)findViewById(R.id.Button03);
bt4 = (Button)findViewById(R.id.Button04);
bt.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
an.setFillAfter(true);
img.startAnimation(an);
return false;
}
});
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
img.startAnimation(an1);
}
});
bt3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
an2.setFillAfter(true);
img.startAnimation(an2);
}
});
bt4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
an3.setFillAfter(true);
img.startAnimation(an3);
}
});
}
}
答案 0 :(得分:0)
你基本上拥有你需要的一切。您只需将矩阵上的旋转更改10度,然后将其应用于用于ImageView的图像。由于您已经将图像旋转180°,因此您应该熟悉需要再旋转10度......
示例代码:
public boolean onTouch(View v, MotionEvent event) {
mat.postRotate(10); // or -10 degree
Bitmap rtd = Bitmap.createBitmap(bmp, 0, 0, w, h, mat, true);
BitmapDrawable bmd = new BitmapDrawable(rtd);
img.setImageDrawable(bmd);
}