Android应用程序需要一个可旋转的圆圈。自定义对象还是小部件?

Android应用程序需要一个可旋转的圆圈。自定义对象还是小部件?,android,widget,rotation,Android,Widget,Rotation,我需要为我的应用程序创建一个旋转并包含数据的圆。我应该为我的应用程序创建一个自定义对象,还是应该创建一个应用程序内小部件 在本主题中,您如何引用应用程序中的小部件而不是android桌面上的独立小部件 有一种相当简单的方法可以从该类派生的自定义小部件制作旋转动画。创建视图并将其放置在布局中后,可以调用视图.setAnimation(Animation)或视图.startAnimation(Animation),在视图上提供一个。下面是一个用xml定义的旋转动画示例,可以使用getResource

我需要为我的应用程序创建一个旋转并包含数据的圆。我应该为我的应用程序创建一个自定义对象,还是应该创建一个应用程序内小部件


在本主题中,您如何引用应用程序中的小部件而不是android桌面上的独立小部件

有一种相当简单的方法可以从该类派生的自定义小部件制作旋转动画。创建视图并将其放置在布局中后,可以调用
视图.setAnimation(Animation)
视图.startAnimation(Animation)
,在视图上提供一个。下面是一个用xml定义的旋转动画示例,可以使用
getResources().getAnimation(int)
从活动中加载该动画


这是一个可旋转的线性布局,您可以将所有内容放入其中,如果您自定义它,您可以按度旋转它。使用rotate()方法旋转它,然后

享受!;)

更新:

将此代码添加到xml布局中,并将ImageView或其他LinearLayout等视图放入其中:

<org.mabna.order.ui.RotateLinearLayout  android:id="@+id/llParent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="horizontal" >



<ImageView
                        android:id="@+id/myImage"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dip"
                        android:src="@drawable/main01" />

</org.mabna.order.ui.RotateLinearLayout>
在按钮的onClickListener中:

protected void btnRotate_onClick() {
        llParent.rotate();
    }
更新2:

可以在实际旋转之前使用动画进行旋转(
llParent.rotate();
)。它需要类似rotate_dialog.xml的动画布局:

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

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000" android:fromDegrees="-180" android:toDegrees="0"
    android:pivotX="50%" android:pivotY="50%" android:fillAfter="true" />

谢谢!但是我不知道如何使用这个代码。在setContentView中设置什么?如何将对象(旋转圆)添加到此视图?我假设这是一个使旋转成为可能的框架。我习惯于在xml中看到LinearLayout,所以如果是在Java中,我不知道如何以编程方式使用它。我应该如何使用此视图?谢谢,我是新来的哈哈,谢谢你!如果我能不止一次投你一票,我会的。单击按钮时,我遇到一些错误。这种观点的行为是什么?如果我单击按钮,视图将旋转180度?错误是在调用RotateLineEarlayout类实例llparent的rotate方法时发生的。错误是什么?您是否自定义了org.mabna.order.ui.RotateLineEarlayout的名称空间我之前的错误是由于错误地处理了click事件。我已经把它修好了,所以按钮是有反应的。但是在llParent上调用rotate()方法时仍然有一个错误。findViewById(R.id.llParent)似乎不起作用,因为llParent为null。稍后进行的一些事实检查表明,我在设置ContentView之前调用了findViewById
llParent = (RotateLinearLayout) this.findViewById(R.id.llParent);
protected void btnRotate_onClick() {
        llParent.rotate();
    }
<?xml version="1.0" encoding="utf-8"?>

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000" android:fromDegrees="-180" android:toDegrees="0"
    android:pivotX="50%" android:pivotY="50%" android:fillAfter="true" />
protected void btnRotate_onClick() {
        // rotate 
        Animation rotateAnimation = AnimationUtils.loadAnimation(this,
                R.anim.rotate_dialog);
        llParent.startAnimation(rotateAnimation);
        llParent.rotate();
    }