您的位置:首页 > 移动开发 > Android开发

Android 两Activity之间动画效果(3)---------缩放,仿QQ头像点击放大

2013-08-28 10:57 726 查看
这篇文章要实现的效果是,点击头像之后,图片要放大占满全屏,又不失真

因为有了前面两篇文章的基础,所以不再详细解释,只写关键部分两xml 如下

img_scale_in:

<?xml version="1.0" encoding="utf-8"?>
<!-- android:fromXScale="0.001" -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="0.001"
android:fromYScale="0.001"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />

Img_scale_out:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.001"
android:toYScale="0.001" />

其中 fromXScale 范围0到无限大 1.0代表图像本身多大就多大,不会放大和缩小,比1小是缩小,比1大是放大最后在AndroidManifest属性里面配置下activity Theme

<activity
android:name=".ShowImagePage"
android:label="@string/title_activity_main"
android:theme="@style/ImageScale" >
</activity>

再有一个小知识,因为要在两个Activity之间要传递bitmap,所以顺带把关键代码贴出来:

传递:

Intent intent = new Intent(this, ShowImagePage.class);

// intent传递bitmap

ByteArrayOutputStream baos = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);

byte[] bitmapByte = baos.toByteArray();

intent.putExtra("bitmap", bitmapByte);

this.startActivity(intent);

接收:

Intent intent = getIntent();

if (intent != null)

{

byte[] bis = intent.getByteArrayExtra("bitmap");

bitmap = BitmapFactory.decodeByteArray(bis, 0, bis.length);

}

源码下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: