TOP

自定义View等待旋转(一)
2017-10-12 10:09:51 】 浏览:10194次 本网站的内容取自网络,仅供学习参考之用,绝无侵犯任何人知识产权之意。如有侵犯请您及时与本人取得联系,万分感谢。
Tags:定义 View 等待 旋转

效果图

 

1 string.xml

<string name="default_progressbar">Default Progressbar:</string>

2 attrs.xml

<resources>

<declare-styleable name="ProgressWheel">
<attr name="matProg_progressIndeterminate" format="boolean" />
<attr name="matProg_barColor" format="color" />
<attr name="matProg_rimColor" format="color" />
<attr name="matProg_rimWidth" format="dimension" />
<attr name="matProg_spinSpeed" format="float" />
<attr name="matProg_barSpinCycleTime" format="integer" />
<attr name="matProg_circleRadius" format="dimension" />
<attr name="matProg_fillRadius" format="boolean" />
<attr name="matProg_barWidth" format="dimension" />
<attr name="matProg_linearProgress" format="boolean" />
</declare-styleable>

</resources>

3 activity_main.xml

<com.etoury.myapplication.ProgressWheel
android:id="@+id/progress_wheel"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
wheel:matProg_barColor="#5588FF"
wheel:matProg_progressIndeterminate="true" />

4 ProgressWhell.java

public class ProgressWheel extends View {
private static final String TAG = ProgressWheel.class.getSimpleName();
private final int barLength = 16;
private final int barMaxLength = 270;
private final long pauseGrowingTime = 200;
/**
* *********
* DEFAULTS *
* **********
*/
//Sizes (with defaults in DP)
private int circleRadius = 28;
private int barWidth = 4;
private int rimWidth = 4;
private boolean fillRadius = false;
private double timeStartGrowing = 0;
private double barSpinCycleTime = 460;
private float barExtraLength = 0;
private boolean barGrowingFromFront = true;
private long pausedTimeWithoutGrowing = 0;
//Colors (with defaults)
private int barColor = 0xAA000000;
private int rimColor = 0x00FFFFFF;

//Paints
private Paint barPaint = new Paint();
private Paint rimPaint = new Paint();

//Rectangles
private RectF circleBounds = new RectF();

//Animation
//The amount of degrees per second
private float spinSpeed = 230.0f;
//private float spinSpeed = 120.0f;
// The last time the spinner was animated
private long lastTimeAnimated = 0;

private boolean linearProgress;

private float mProgress = 0.0f;
private float mTargetProgress = 0.0f;
private boolean isSpinning = false;

private ProgressCallback callback;

private boolean shouldAnimate;

/**
* The constructor for the ProgressWheel
*/
public ProgressWheel(Context context, AttributeSet attrs) {
super(context, attrs);

parseAttributes(context.obtainStyledAttributes(attrs, R.styleable.ProgressWheel));

setAnimationEnabled();
}

/**
* The constructor for the ProgressWheel
*/
public ProgressWheel(Context context) {
super(context);
setAnimationEnabled();
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void setAnimationEnabled() {
int currentApiVersion = Build.VERSION.SDK_INT;

float animationValue;
if (currentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
animationValue = Settings.Global.getFloat(getContext().g

请关注公众号获取更多资料


自定义View等待旋转(一) https://www.cppentry.com/bencandy.php?fid=98&id=144789

首页 上一页 1 2 3 4 5 6 下一页 尾页 1/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇设计模式——适配器模式 下一篇Android笔记——Android中数据的..

评论

验 证 码:
表  情:
内  容: