如何在android中的appwidget中制作动画视图

时间:2013-12-30 06:11:29

标签: android

我的应用程序中有一个小部件,小部件包含一些ImageView,但我需要在小部件中为视图设置动画,使用ViewFlipper我可以做到,但它支持API + 11,如何以下面的版本制作它,即使可能以任何其他方式被赞赏

public class MyAnimationWidget extends AppWidgetProvider {

private Handler handler;
private Context context;
private Runnable myRunnnable = new Runnable() {
    @Override
    public void run() {
        updateWidget(context);
        handler.postDelayed(this, 1000);

    }
};
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    this.context = context;
    if (handler == null) {
        handler = new Handler();
        handler.postDelayed(myRunnnable, 2000);
    }
}
private void updateWidget(Context context) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
            R.layout.activity_main);
    remoteViews.showNext(R.id.view_flipper);
    ComponentName componentName = new ComponentName(context,
            MyAnimationWidget.class);
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
    widgetManager.updateAppWidget(componentName, remoteViews);
}
}

这是我的widget_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/myshape"
    android:orientation="vertical" >

    <ViewFlipper
        android:id="@+id/view_flipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:inAnimation="@anim/in_from_left"
        android:outAnimation="@anim/out_to_right" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:src="@drawable/algeria" />
    </ViewFlipper>

</LinearLayout>

0 个答案:

没有答案