android开发转盘按钮,Android中的转盘

如何借助touch事件在Android上的活动中旋转图像轮?我需要一些指南或任何教程的链接.

解决方法:

这通常需要几块.这就是我在其中一个应用程序中执行此操作的方式. *注意:这不是一个平滑的轮子,因为它在顶部开始和停止(这是有意的).您可以在dev site上查找有关Animation的更多信息.

具有图像的主要XML:

android:id="@+id/anim_example"

android:src="@drawable/loading_circle"

android:layout_width="30sp"

android:layout_height="30sp"

android:onClick="RunAnimation" />

这是运行动画的代码部分

public void RunAnimation(View v)

{

//The onClick method has to be present and must take the above parameter.

StartLoading();

//This will delay the stop for 5 seconds

//Normally you would want to actually have this run based on some other input/data.

Handler handler = new Handler();

handler.postDelayed(new Runnable() {

public void run() {

StopLoading();

}

}, 5000);

}

public void StartLoading() {

ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example);

refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle));

Animation rotateLoading = AnimationUtils.loadAnimation(this, R.anim.rotate);

refreshImage.clearAnimation();

refreshImage.setAnimation(rotateLoading);

}

public void StopLoading() {

ImageView refreshImage = (ImageView) this.findViewById(R.id.anim_example);

if (refreshImage.getAnimation() != null)

{

refreshImage.clearAnimation();

refreshImage.setImageDrawable(getResources().getDrawable(R.drawable.loading_circle));

}

}

动画旋转:

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

android:fromDegrees="0"

android:toDegrees="359"

android:duration="2000"

android:repeatMode="restart"

android:repeatCount="-1"

android:pivotX="50%"

android:pivotY="50%">

标签:android

来源: https://codeday.me/bug/20191208/2088764.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然,我可以为您提供一个简单的示例代码来创建一个转盘效果。请注意,这只是一个基本的示例,您可以根据自己的需求进行修改和扩展。 首先,在布局文件添加一个ImageView来显示转盘图像: ```xml <ImageView android:id="@+id/wheel" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/wheel_image" android:rotation="0" /> ``` 接下来,在Java类获取ImageView的引用,并为其添加旋转动画: ```java import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { private ImageView wheel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); wheel = findViewById(R.id.wheel); // 加载旋转动画 Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate); // 设置旋转动画的一些属性(可选) rotation.setRepeatCount(Animation.INFINITE); // 无限循环 rotation.setInterpolator(new LinearInterpolator()); // 匀速旋转 // 启动旋转动画 wheel.startAnimation(rotation); } } ``` 接下来,我们需要在`res`文件夹下的`anim`文件夹创建一个`rotate.xml`文件,并定义旋转动画: ```xml <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:duration="2000" android:fromDegrees="0" android:toDegrees="360" /> ``` 这个示例的旋转动画会使转盘无限循环地旋转一周。 请注意,您需要将`wheel_image`替换为您自己的转盘图像资源。 希望这个示例对您有所帮助!如果您有任何其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值