自定義View動畫圓形進度跳轉
阿新 • • 發佈:2019-01-13
下面寫一個簡單版的動畫載入百分比跳轉
我發的這個是個簡單版的,配置檔案什麼的都已經配完,都在依賴裡面,你們只需要把這個依賴倒進去就可以呼叫了
1.先把依賴導進去
//圓形進度條
implementation 'com.czp.arcProgressBar:ArcProgressBar:1.0.1'
2.佈局
<LinearLayout android:orientation="vertical" 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=".ui.activity.MainActivity"> <com.czp.library.ArcProgress android:layout_marginTop="50dp" android:id="@+id/myprogreen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </LinearLayout>
3.這是主頁面的效果
import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.SystemClock; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; import android.widget.Toast; import com.czp.library.ArcProgress; import com.czp.library.OnTextCenter; import butterknife.ButterKnife; import gsp.com.progreen.R; public class MainActivity extends AppCompatActivity { //handler private Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { ArcProgress obj = (ArcProgress) msg.obj; obj.setProgress(msg.what); return true; } }); private ArcProgress myprogreen1; private TextView text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); myprogreen1 = findViewById(R.id.myprogreen); text = findViewById(R.id.text); myprogreen1.setOnCenterDraw(new OnTextCenter(Color.RED, 20)); new Thread(new Runnable() { @Override public void run() { //for判斷 for (int i = 0; i < 101; i++) { //判斷結束 /* */ //判斷結束 if (isFinishing()) { break; } //系統時鐘 睡 100 毫秒 SystemClock.sleep(100); handler.sendMessage(handler.obtainMessage(i, myprogreen1)); if (i ==100){ //跳轉 startActivity(new Intent(MainActivity.this, TwoActivity.class)); finish(); } } } }).start(); } }
下面我把效果圖給大家發出來,當到達100的時候跳轉頁面,寫的不好還望多多見諒,還望大神能多多指點一下