problem animating a view

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

problem animating a view

Postby cafffiene » Mon Aug 31, 2009 9:59 pm

Attempting a fairly simple animation of a View. The code below is partly inspired by a tutorial posted to this forum using ColorBalls class.

I'm trying to display a panel, and then just animate it if the user touches the screen.

Code for my simplified test is below.

the function animateMe() definitely gets called, but nothing happens.

Any help greatly appreciated, thanks.

er...sorry about the formatting, hope its readable.




MAIN FILE:

public class MovePanelsPCT2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
setContentView(new DrawView(this));
}
}




DRAW VIEW CLASS:

public class DrawView extends View {
private Panel myPanel;
Point point0 = new Point();

public Context myContext = null;

public DrawView(Context context) {
super(context);
setFocusable(true); //necessary for getting the touch events
myContext = context;
point0.x = 20;
point0.y = 0;
myPanel = new Panel(context,R.drawable.green_panel, point0);
}

@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(myPanel.getBitmap(), myPanel.getX(), myPanel.getY() , null);
}

public boolean onTouchEvent(MotionEvent event) {
myPanel.animateMe();
invalidate();
return true;
}
}


PANEL CLASS:

public class Panel extends View {
private Bitmap img; // the image of the panel
private int coordX = 0; // the x coordinate at the canvas
private int coordY = 0; // the y coordinate at the canvas
private RotateAnimation anim2 = null;

public Panel(Context context, int drawable, Point point) {
super(context);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
img = BitmapFactory.decodeResource(context.getResources(), drawable);
coordX = point.x;
coordY = point.y;
}

public void animateMe (){
anim2=new RotateAnimation(0.0f, 90.0f);
anim2.setDuration(1000);
anim2.setInterpolator(new AccelerateInterpolator(1.0f));
startAnimation(anim2);

}

public int getX() {
return coordX;
}

public int getY() {
return coordY;
}
public Bitmap getBitmap() {
return img;
}
}
cafffiene
Freshman
Freshman
 
Posts: 2
Joined: Mon Aug 31, 2009 9:43 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 11 guests