2018. 7. 12. 16:54ㆍAndroid
ㅇ res > drawable > circular_progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="2dp"
android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->
<gradient
android:angle="0"
android:endColor="@color/colorPrimary"
android:startColor="@color/colorPrimary"
android:type="sweep"
android:useLevel="false"/>
</shape>
</rotate>
ㅇ res > drawable > circle_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="2.5"
android:thickness="2dp"
android:useLevel="false">
<solid android:color="#FFFFFF" />
</shape>
ㅇ res > layout > layout_main.xml
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:progressDrawable="@drawable/circular_progressbar"
android:indeterminateDrawable="@drawable/circular_progressbar"
android:background="@drawable/circle_shape"
android:indeterminate="false"
android:max="100"
android:visibility="gone"/>
ㅇ MainActivity.java
private ProgressBar mProgress_bar;
private ObjectAnimator mObjectAnimator;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
mProgress_bar = (ProgressBar) findViewById(R.id.progress_bar);
}
void showProgressBar(){
mProgress_bar.setVisibility(View.VISIBLE);
final int FIRST = 0, MAX = mProgress_bar.getMax(), DURATION = 3000;
mProgress_bar.setProgress(0);
mProgress_bar.post(new Runnable() {
@Override
public void run() {
for(int i=0; i<=MAX; i++){
mProgress_bar.setProgress(i);
}
}
});
if(mObjectAnimator == null) mObjectAnimator = ObjectAnimator.ofInt(mProgress_bar, "progress", FIRST, MAX);
mObjectAnimator.setDuration(DURATION);
mObjectAnimator.setInterpolator(new DecelerateInterpolator());
mObjectAnimator.start();
}
void hideProgressBar(){
if(mObjectAnimator != null && mObjectAnimator.isRunning()) mObjectAnimator.end();
mProgress_bar.setVisibility(View.GONE);
}
'Android' 카테고리의 다른 글
밀도(Density) (0) | 2018.08.14 |
---|---|
안드로이드 9.0(파이) (0) | 2018.08.10 |
Notification (0) | 2018.07.07 |
FCM 서버(Spring) 연동 (0) | 2018.07.07 |
FCM 푸시알림시 화면깨우기 (0) | 2018.07.07 |