我正在创建一个Android应用程序,我必须在网格视图中旋转图像。我写了以下代码:
public boolean onTouch(View v, MotionEvent me) {
.............
int position = parent.pointToPosition(x, y);
switch(me.getAction())
{
case MotionEvent.ACTION_DOWN :
//int z = fPosition(x,y);
sr = position;
doRotation(v,position);
//startAnimation(v);
//Toast.makeText(GameActivity.this, "down "+position,Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_UP :
//popUp.dismiss();
ds = position;
images.cPositions(sr,ds);
images.notifyDataSetChanged();
//int z1 = fPosition(x,y);
//Toast.makeText(GameActivity.this, "up " + position, Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_MOVE :
//Toast.makeText(GameActivity.this, "move", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
void doRotation(View v, int position) {
final ImageView im;
final RotateAnimation rAnim;
ViewGroup vg = (ViewGroup) findViewById(R.id.mlinear);
rAnim = new RotateAnimation(0f,360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rAnim.setStartOffset(0);
rAnim.setDuration(2000);
rAnim.setFillAfter(true);
rAnim.setFillEnabled(true);
v.startAnimation(rAnim);
}
我在Android 2.2(8级)它做的是它的旋转整个网格视图我想要旋转图像。只是想知道如何在网格视图中获取图像的图像视图..
答案 0 :(得分:0)
我认为您GridView
正在设置onTouchListener
。这就是为什么它旋转整个视图。尝试在GridView中为视图设置Listener。最好实现setOnItemClickListener
,以便您可以轻松获取所点击的项目。