`

Dialog伸缩动画效果

阅读更多
效果图:




ViewScale.java:
public class ViewScale extends Activity implements OnClickListener {

	private LinearLayout mLayout;
	private Animation mScaleIn, mScaleOut;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mScaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);
		mScaleOut = AnimationUtils.loadAnimation(this, R.anim.scale_out);
		mLayout = (LinearLayout) findViewById(R.id.mLayout);
		Button btn = (Button) findViewById(R.id.btn);
		btn.setOnClickListener(this);

		iv = new ImageView(ViewScale.this);
		LinearLayout.LayoutParams mParam = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		iv.setLayoutParams(mParam);
		iv.setBackgroundResource(R.drawable.belle_frame);
	}

	private int i = 0;
	private ImageView iv;

	@Override
	public void onClick(View v) {
		if (i % 2 == 0) {
			mLayout.addView(iv);
			iv.startAnimation(mScaleOut);
			mScaleOut.setAnimationListener(new AnimationListener() {
				@Override
				public void onAnimationStart(Animation animation) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onAnimationEnd(Animation animation) {
					// TODO Auto-generated method stub
					// mLayout.removeView(iv);
				}

				@Override
				public void onAnimationRepeat(Animation animation) {
					// TODO Auto-generated method stub

				}
			});
		} else {
			iv.startAnimation(mScaleIn);
			mScaleIn.setAnimationListener(new AnimationListener() {
				@Override
				public void onAnimationStart(Animation animation) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onAnimationEnd(Animation animation) {
					// TODO Auto-generated method stub
					mLayout.removeView(iv);
				}

				@Override
				public void onAnimationRepeat(Animation animation) {
					// TODO Auto-generated method stub

				}
			});
		}
		i++;

	}

}



scale_out.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<scale android:interpolator="@android:anim/accelerate_interpolator"
		android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0"
		android:toYScale="1.0" android:pivotX="1%" android:pivotY="1%"
		android:fillAfter="true" android:duration="400" />
</set>


scale_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<scale android:interpolator="@android:anim/accelerate_interpolator"
		android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0"
		android:toYScale="0.0" android:pivotX="1%" android:pivotY="1%"
		android:fillAfter="true" android:duration="400" />
</set>

  • 大小: 5.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics