PowenKo, Android Tutorial 085-5, Animation,Scale

September 8, 2011   ·   0 Comments

package com.powenko.Tutorial_Animation_ScaleAnimation;




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.ScaleAnimation;
import android.widget.AbsoluteLayout;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;

public class Tutorial_Animation_ScaleAnimationActivity 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() {
                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);
            
            
            ScaleAnimation anim = new ScaleAnimation((float)1.0, (float)1.5, (float)1.0, (float)1.5);
            anim.setFillAfter(true);
            anim.setDuration(500);
            //imageView.startAnimation(scale);
            
            
            
            
            
            
            // anim.setDuration(1000);
            container.addView(toAdd);
            //container.invalidate(); 
            toAdd.startAnimation(anim);
            
            
        
        }
    };

        
}

res\layout\main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>

<AbsoluteLayout
android:id="@+id/absLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</AbsoluteLayout>
</LinearLayout>
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