PowenKo, Android Tutorial 085-2, Animation,Animation_Alpha

August 25, 2011   ·   0 Comments

package com.powenko.Tutorial_Animation_Alpha;

import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.widget.AbsoluteLayout;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;

public class Tutorial_Animation_AlphaActivity extends Activity {
    /** Called when the activity is first created. */
    Button btn = null;
    AbsoluteLayout container = null;
    int counter = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        container = (AbsoluteLayout)findViewById(R.id.absLayout);
        ImageView toAdd = new ImageView(this);
       // generate();
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                timerMethod();
            }
        }, 0,1000);

    }
    private void timerMethod()
    {
    this.runOnUiThread(generate);
    }
    private Runnable generate= new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            Log.i("MARKER","******************************************");
            //int numViews = container.getChildCount();
            Context context = getApplicationContext();
            ImageView toAdd = new ImageView(context);
            Drawable imgContent = context.getResources().getDrawable(R.drawable.icon);
            toAdd.setImageDrawable(imgContent);
            toAdd.setTag("img"+counter++);

            Random rndGen = new Random();
            LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,rndGen.nextInt(300),rndGen.nextInt(300));
            toAdd.setLayoutParams(lp);
            toAdd.setBackgroundColor(Color.TRANSPARENT);

            AlphaAnimation anim = new AlphaAnimation(0, 1);
            anim.setDuration(1000);
            container.addView(toAdd);
            //container.invalidate();
            toAdd.startAnimation(anim);

        }
    };

}
<!--?xml version="1.0" encoding="utf-8"?-->

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon