如何实现一个翻页效果的widget

说一下思路,widget是一个RemoteView,更新方式有些特殊,我在网上找了很久,最终想起来一个同事做过这种效果,把他的源码拿过来看了下。他的思路是在布局里给LinearLayout设置动画属性,把自己想加载动画的视图放进去就行了。

我们这里实现的效果是垂直往下翻页。

其实就是一个图片缩放动画。这里为了更细致点,可以拆分成两个部分:上半页高度由0慢慢放大到100%,接着下半部分宽度由0慢慢放大到100%.


可以在布局里先写好动画:

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:layout_weight="@integer/pageturning_layout_weight_top"> <!--固定高度比例,缩放时视图不会变形-->

 

            <LinearLayout

                android:id="@+id/topnewnum_h"

                android:layout_width="fill_parent"

                android:layout_height="fill_parent"

                android:layoutAnimation="@anim/la_pageturning_top" >

                <ImageView

                    android:id="@+id/topnewhalf_h"

                    android:layout_width="fill_parent"

                    android:layout_height="fill_parent"

                    android:scaleType="fitXY" />

            </LinearLayout>

    </LinearLayout>

    <LinearLayout

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:layout_weight="@integer/pageturning_layout_weight_bottom" >

            <LinearLayout

                android:id="@+id/bottomnewnum_h"

                android:layout_width="fill_parent"

                android:layout_height="fill_parent"

                android:layoutAnimation="@anim/la_pageturning_bottom">

                <ImageView

                    android:id="@+id/bottomnewhalf_h"

                    android:layout_width="fill_parent"

                    android:layout_height="fill_parent"

                    android:scaleType="fitXY" />

            </LinearLayout>

    </LinearLayout>

</LinearLayout>


重点在于中间的那行红色代码,在widget中,我们一般不能在代码中给视图添加动画,所以就使用这种方法变通一下。就可以达到效果了。至于动画文件,大家就自己定义吧。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值