图片显示

package cn.com.dne.scleanimation;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class ScleAnimation extends Activity implements OnClickListener {   
  
    RelativeLayout layout_parent;   
       
    Button scale_btn;   
  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);   
        setContentView(R.layout.first);   
  
        scale_btn = (Button) findViewById(R.id.scale_btn);   
        scale_btn.setOnClickListener(this);   
  
        layout_parent = (RelativeLayout) findViewById(R.id.layout_parent);   
    }   
  
    @Override  
    public void onClick(View v) {   
        // TODO Auto-generated method stub   
        switch (v.getId()) {   
        case R.id.scale_btn:   
            displayPage();   
            v.setEnabled(false);   
            break;   
        case R.id.dismiss_btn:   
            dismissPage();   
            break;   
        }   
  
    }   
  
    View layout;   
    ImageView jobShadow;   
  
    public void displayPage() {   
        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);   
        layout = inflater.inflate(R.layout.second, null);   
        layout.setId(Constant.KEY_LAYOUT_ID);   
        jobShadow = (ImageView) layout.findViewById(R.id.jobShadow);   
  
        Drawable ico = getResources().getDrawable(R.drawable.icon);   
        jobShadow.setBackgroundDrawable(ico);   
        ico.mutate().setAlpha(200);   
  
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(   
                LinearLayout.LayoutParams.FILL_PARENT,   
                LinearLayout.LayoutParams.FILL_PARENT);   
        layout_parent.addView(layout, layoutParams);   
  
        findDialogView();    
        ScaleAnimationHelper sAnimationHelper=new ScaleAnimationHelper(this, Constant.KEY_FIRSTPAGE);
        sAnimationHelper.ScaleInAnimation(layout);
    }   
  
    public void removeLayout() {   
  
        layout_parent.removeView(layout_parent   
                .findViewById(Constant.KEY_LAYOUT_ID));   
    }   
  
    Button dismiss_btn;   
  
    public void findDialogView() {   
        dismiss_btn = (Button) findViewById(R.id.dismiss_btn);   
        dismiss_btn.setOnClickListener(this);   
    }   
  
    public void dismissPage() {   
        ScaleAnimationHelper scaleHelper = new ScaleAnimationHelper(this,Constant.KEY_SECONDPAGE);   
        scaleHelper.ScaleInAnimation2(layout);   
        scale_btn.setEnabled(true);   
    }   
}  

 

package cn.com.dne.scleanimation;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;

public class ScaleAnimationHelper {
	Context con;
	int order;
	Object obj;

	public ScaleAnimationHelper(Context con, int order) {
		this.con = con;
		this.order = order;
	}
	
	public ScaleAnimationHelper(Object obj, Context con, int order)
	{
		this.obj = obj;
		this.con = con;
		this.order = order;
	}

	DisplayNextView listener;
	ScaleAnimation myAnimation_Scale;

	// 放大的类,不需要设置监听器
	public void ScaleOutAnimation(View view) {
		myAnimation_Scale = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		myAnimation_Scale.setInterpolator(new AccelerateInterpolator());
		AnimationSet aa = new AnimationSet(true);
		aa.addAnimation(myAnimation_Scale);
		aa.setDuration(500);

		view.startAnimation(aa);
	}

	public void ScaleInAnimation(View view) {

		listener = new DisplayNextView((Activity) con, order);

		myAnimation_Scale = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		myAnimation_Scale.setInterpolator(new AccelerateInterpolator());
		myAnimation_Scale.setAnimationListener(listener);
		AnimationSet aa = new AnimationSet(true);
		aa.addAnimation(myAnimation_Scale);
		aa.setDuration(1000);
		view.startAnimation(aa);
	}

	public void ScaleInAnimation2(View view)
	{
		if (obj != null)
		{
			listener = new DisplayNextView(obj, (Activity) con, order);
		} else
		{
			listener = new DisplayNextView((Activity) con, order);
		}

		myAnimation_Scale = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		myAnimation_Scale.setAnimationListener(listener);
		myAnimation_Scale.setInterpolator(new AccelerateInterpolator());

		AnimationSet aa = new AnimationSet(true);
		aa.addAnimation(myAnimation_Scale);
		aa.setDuration(1000);

		view.startAnimation(aa);
	}

}

 

package cn.com.dne.scleanimation;

import android.app.Activity;
import android.provider.SyncStateContract.Constants;
import android.view.View;
import android.view.animation.Animation;
import android.widget.RelativeLayout;

public class DisplayNextView implements Animation.AnimationListener {   
  
    Object obj;   
  
    // 动画监听器的构造函数   
    Activity ac;   
    int order;   
  
    public DisplayNextView(Activity ac, int order) {   
        this.ac = ac;   
        this.order = order;   
    }   
  
	public DisplayNextView(Object obj, Activity ac, int order)
	{
		this.obj = obj;
		this.ac = ac;
		this.order = order;
	}
    
    public void onAnimationStart(Animation animation) {   
    }   
  
    public void onAnimationEnd(Animation animation) {   
        doSomethingOnEnd(order);   
    }   
  
    public void onAnimationRepeat(Animation animation) {   
    }   
  
    private final class SwapViews implements Runnable {   
        public void run() {   
            switch (order) {   
            case Constant.KEY_SECONDPAGE:   
                ((ScleAnimation) ac).removeLayout();   
                
                RelativeLayout rl = (RelativeLayout) ((ScleAnimation) ac)
				.findViewById(R.id.layout_parent);
		rl.removeView((View) ((ScleAnimation) ac)
				.findViewById(Constant.KEY_LAYOUT_ID));
                break;   
            }   
        }   
    }   
  
    public void doSomethingOnEnd(int _order) {   
        switch (_order) {   
           
        case Constant.KEY_SECONDPAGE:   
        	 ((ScleAnimation) ac).layout_parent.post(new SwapViews()); 
          
            break;   
        }   
    }   
}  

 

package cn.com.dne.scleanimation;

public class Constant {

	public final static int KEY_FIRSTPAGE = 1;

	public final static int KEY_SECONDPAGE = 2;

	public final static int KEY_LAYOUT_ID = 3;
  public final static int KEY_SELECTJOB_LAYOUT_ID=12;
}

 

<?xml version="1.0" encoding="utf-8"?>   
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical" android:layout_width="fill_parent"  
    android:layout_height="fill_parent" android:id="@+id/layout_parent">   
    <Button android:text="Scale" android:id="@+id/scale_btn"  
        android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>   
</RelativeLayout>  

 

<?xml version="1.0" encoding="utf-8"?>   
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent" android:layout_height="fill_parent"  
    android:id="@+id/jobContent">   
    <ImageView android:layout_width="fill_parent"  
        android:layout_height="fill_parent" android:id="@+id/jobShadow" />   
    <Button android:layout_width="fill_parent" android:text="Dismiss"  
        android:layout_marginTop="20dp" android:layout_height="wrap_content"  
        android:src="@drawable/icon" android:layout_alignParentBottom="true"  
        android:id="@+id/dismiss_btn" />   
</RelativeLayout>  


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhchzh1000

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值