您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“Android如何自定義加載圈”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
<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如何自定義加載圈”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。