Bump: Can anyone help? If I define an imageview in my activity and
then set an animation for it, then it plays fine. But if I define an
image view as a member in my custom view and then try to play its
animation, it does not play. Any help is appreciated...

On Dec 18, 4:59 pm, Seb <stsiop...@googlemail.com> wrote:
> I am creating a game. Most of the computation is done in acustomView
> class which contains a grid ofcustomSquares which extendimageview.
> Here's some code to describe what's happening:
>
> public class GameView extends View {
> public Square squares[] = null;
>
> public GameView(Context context, AttributeSet a) {
>     super(context, a);
>     setFocusable(true);
>
> }
>
> @Override
> protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
> {
>     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
>     squares = new Square[numSquares];
>
> }
>
> public void resetGame()
> {
>
> }
>
> public void restartGame()
> {
>
> }
>
> public boolean onTouchEvent(MotionEvent event) {
>     int eventaction = event.getAction();
>     int X = (int)event.getX();
>     int Y = (int)event.getY();
>
>     switch (eventaction)
>     {
>     case MotionEvent.ACTION_DOWN:
>         currentTouchIndex = checkForSquareTouch(X, Y);
>
>         if(currentTouchIndex >= 0)
>         {
>             squares[currentTouchIndex].select();
>             ((MainActivity)this.getContext()).startSquareAnimation();
>
>         .........
>     return true;
>
> }
>
> Thats the main View. Square implementation:
>
> public class Square extendsImageView{
>
> public Square(Context context, AttributeSet attrs, int x, int y,
>         int squareWidth, boolean operator, int textS, Typeface f) {
>     super(context, attrs);
> {
>             this.setImageResource(R.drawable.chalkbox);
>     this.getDrawable().setBounds(x, y, x + squareWidth, y +
> squareWidth);
>
>     this.setAlpha(10);
>
> }
>
> protected void onDraw(Canvas canvas) {
>     Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG);
>     foreground.setStyle(Style.FILL);
>     foreground.setTextSize(textSize);
>     foreground.setColor(Color.WHITE);
>     foreground.setTextScaleX(1);
>     foreground.setTextAlign(Paint.Align.CENTER);
>     foreground.setTypeface(font);
>
>     int left = this.getDrawable().getBounds().left;
>     int right = this.getDrawable().getBounds().right;
>     int top = this.getDrawable().getBounds().top;
>     int bottom = this.getDrawable().getBounds().bottom;
>
>     if (invalidMove) {
>
>     }
>
>     if (isOperator) {
>         if (text.equals("+"))
>             bottom += 10;
>
>         if (text.equals("/"))
>             bottom += 5;
>
>         if (text.equals("x") || text.equals("/"))
>             foreground.setTextSize(textSize - 5);
>         else
>             foreground.setTextSize(textSize);
>     }
>
>     this.getDrawable().draw(canvas);
>     canvas.drawText(text, (left + right) / 2, ((top + bottom) / 2) +
> 10, foreground);
>
> }
>
> Hope that gives you a view of the structure. I'm trying to animate the
> Square, so that when a player presses on a Square, the Square
> brightens and then fades again when they lift their finger off. The
> problem is that the call to square[0].startAnimation() does not seem
> to be working and theanimationis not playing. Am I doing something
> wrong?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to