你的位置:首页 > 软件开发 > 操作系统 > AnimationsDemo中的ZoomActivity代码分析

AnimationsDemo中的ZoomActivity代码分析

发布时间:2015-04-10 17:00:34
AnimationsDemo是android官网的一个动画使用示例。 ZoomActivity是demo中的图像缩放动画,因为这种效果比较常见,所以研究了一下代码。 下面是效果图: 毫无疑问这是一个组合动画,translation和scale动画.实现这种动画的关键是如何确定动 ...

AnimationsDemo中的ZoomActivity代码分析

AnimationsDemo是android官网的一个动画使用示例。

ZoomActivity是demo中的图像缩放动画,因为这种效果比较常见,所以研究了一下代码。

下面是效果图:

AnimationsDemo中的ZoomActivity代码分析

毫无疑问这是一个组合动画,translation和scale动画.实现这种动画的关键是如何确定动画的坐标和缩放比例

除了一些简单的数学计算外,该demo还利用了ImageView的fitCenter特性.稍后我们就可以看到.

在开始分析代码之前,先说一下程序的原理:

    1,点击缩略图的时候同时将缩略图隐藏。

    2,载入相应的大图,将大图缩小成缩略图的大小,并设置为Visible

    3,大图缩小后移动到原缩略图的位置,并把它覆盖

    4,被缩小的大图在该位置重新放大

 

为了更清楚的表达这个过程,我将程序改动一下再运行:

AnimationsDemo中的ZoomActivity代码分析

浅绿色部分就是整个ImageView的大小。明白这一点很重要。

 

原理明白了就可以开始分析代码,先来的是程序的布局:

<FrameLayout ="http://schemas.android.com/apk/res/android"       android:id="@+id/container"       android:layout_width="match_parent"       android:layout_height="match_parent">  <LinearLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical"    android:padding="16dp">    <TextView      style="?android:textAppearanceSmall"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="@string/message_zoom_touch_expand"/>    <LinearLayout      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_marginTop="16dp"      android:orientation="horizontal">      <ImageView        android:id="@+id/thumb_button_1"        android:layout_width="100dp"        android:layout_height="75dp"        android:layout_marginRight="1dp"        android:src='/images/loading.gif' data-original="@drawable/thumb1"        android:scaleType="centerCrop"        android:contentDescription="@string/description_image_1"/>      <ImageView        android:id="@+id/thumb_button_2"        android:layout_width="100dp"        android:layout_height="75dp"        android:src='/images/loading.gif' data-original="@drawable/thumb2"        android:scaleType="centerCrop"        android:contentDescription="@string/description_image_2"/>    </LinearLayout>  </LinearLayout>  <ImageView    android:id="@+id/expanded_image"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:visibility="invisible"    android:contentDescription="@string/description_zoom_touch_close"/></FrameLayout>

原标题:AnimationsDemo中的ZoomActivity代码分析

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录