android带动画的圆形进度条

这篇博客介绍了如何在Android中创建一个带有动画效果的圆形进度条。作者通过反编译一个应用发现复杂的实现方式,然后决定寻找替代方案。最终实现了预期效果,并承诺将分享具体的代码和属性文件。
摘要由CSDN通过智能技术生成

偶然发现一个很好的app,圆环进度条,带加速动画,看起来相当不错。尝试着克隆一下。

反编译一看,哇塞,啥3.1415926都干出来了,太高端玩不转啊,算了,想想其它方式吧。

先看效果图:


这个草稿存了小半年.....先发布了再说。实现了预想的效果,具体代码稍后奉上。


代码:

package com.zkbc.finance.widget;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;

import com.zkbc.finance.R;


/**
 * 自定义进度
 *
 * @author Rock Lee
 * @date 2016年4月18日
 */
public class MyProgessLine extends View {

    //需要执行动画的参数名
    private static final String PROGRESS_PROPERTY = "progress";

    private Paint paint;// 画笔

    RectF rectF;

    private int bmColor;// 底部横线颜色
    private float bmHight;// 底部横线高度
    private int color;// 进度条颜色
    private float hight;// 进度条高度

    protected float progress;

    public void setColor(int color) {
        this.color = color;
    }

    public MyProgessLine(Context context) {
        this(context, null);
    }

    public MyProgessLine(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyProgessLine(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs);
        paint = new Paint();
        rectF = new RectF();

        TypedArray mTypedArray = context.getTheme().obtainStyledAttributes(
                attrs, R.styleable.MyProgressLine, defStyleAttr, 0);

        bmColor = mTypedArray.getColor(R.styleable.MyProgressLine_myProgressLine_bmColor,
                Color.GRAY);
        bmHight = mTypedArray
                .
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Android Studio中,创建一个圆角的对话框(通常用于弹出窗口或提示信息)可以通过自定义布局以及使用`android.R.attr.shape`属性来实现。以下是一个简单的步骤: 1. **创建布局**: 使用XML文件创建一个新的对话框布局(例如`rounded_popup_window.xml`),添加一个`FrameLayout`作为根,并设置其背景为半透明的`PopupWindow`背景: ```xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rounded_popup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/transparent" android:padding="16dp" android:elevation="16dp"> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rounded_background"/> <!-- Your content goes here, like TextView or other views --> </FrameLayout> ``` 在这个布局中,`rounded_background.xml`文件用来定义圆角背景: ```xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="16dp" /> <!-- 设置圆角大小 --> <solid android:color="#80000000" /> <!-- 半透明黑色背景 --> </shape> ``` 2. **创建PopupWindow**: 在Java或Kotlin代码中,你可以这样创建并显示有圆角的`PopupWindow`: ```java // 假设你已经有了一个Button或者其他触发事件的控件 Button button = findViewById(R.id.my_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 创建一个圆角的PopupWindow实例 PopupWindow popup = new PopupWindow(RoundedPopupWindow.this, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); // 设置布局 popup.setContentView(R.layout.rounded_popup_window); // 设置弹出位置 popup.showAtLocation(button, Gravity.CENTER, 0, 0); // 其他配置,如动画、点击后消失等 } }); ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值