本篇内容介绍了“Android如何自定义加载圈”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!<RelativeLayout
本篇内容介绍了“Android如何自定义加载圈”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
<RelativeLayout xmlns:android="Http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.tlkg.welcome.loadingviewdemo.MainActivity"> <com.tlkg.welcome.loadingviewdemo.LoadingView android:layout_width="150dp" android:layout_height="150dp" android:layout_centerInParent="true" /></RelativeLayout>
public class LoadingView extends LinearLayout { public LoadingView(Context context) { this(context, null); } public LoadingView(Context context, @Nullable AttributeSet attrs) { this(context, attrs, 0); } public LoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setOrientation(VERTICAL); setGravity(Gravity.CENTER); setBackgroundResource(R.drawable.loadingsp); LoadView loading = new LoadView(getContext()); loading.setLayoutParams(new ViewGroup.LayoutParams(200, 200)); addView(loading); TextView tv = new TextView(getContext()); tv.setText("正在加载中"); LinearLayout.LayoutParams layoutParams = new LayoutParams(-2, -2); layoutParams.setMargins(0, 10, 0, 0); tv.setLayoutParams(layoutParams); tv.setGravity(Gravity.CENTER); tv.setTextColor(Color.WHITE); addView(tv); } class LoadView extends View { Paint mPaint; private int mWidth; private int mHeight; private int mCurrentIndex = 0; private int count = 12; public LoadView(Context context) { super(context); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStyle(Paint.Style.FILL); mPaint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics())); mPaint.setColor(Color.WHITE); } @Override protected void onDraw(canvas canvas) { super.onDraw(canvas); if (mCurrentIndex >= count) { mCurrentIndex = 0; } int endAlpha = 255 / count; for (int i = 0; i < count; i++) { int alpha; if (mCurrentIndex - i > 0) { alpha = endAlpha * (mCurrentIndex - i); } else { alpha = 255 - 255 / count * (i - mCurrentIndex); } mPaint.setColor(Color.argb(alpha, 255, 255, 255)); canvas.drawLine(mWidth / 2, 0, mWidth / 2, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()), mPaint); canvas.rotate(360 / count, mWidth / 2, mHeight / 2); } mCurrentIndex++; postInvalidateDelayed(100); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mWidth = getWidth(); mHeight = getHeight(); } }}
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="5dp" /> <solid android:color="#aa000000" /></shape>
“Android如何自定义加载圈”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!
--结束END--
本文标题: Android如何自定义加载圈
本文链接: https://lsjlt.com/news/341663.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0