Android 프로 세 스 항목 사용 상세 설명 및 예시 코드

13462 단어 Android진도 표
여기 서 loading 진도 항목 의 사용 을 간단하게 정리 합 니 다.
1.진도 조 를 말 할 때 반드시 선형 진도 조 를 말 해 야 합 니 다.자주 사용 하 잖 아 요.특히 파일 다운로드 진도 등 이 있 습 니 다.그리고 텐 센트 QQ 설치 진도 조 처럼 진도 가 있 으 면 좋 은 사용자 체험 을 할 수 있 습 니 다.
먼저 그림 을 찾 아 보 세 요.이 그림 을 완성 하려 면 그림 을 쓰 지 않 아 도 됩 니 다.

xml 레이아웃 파일 을 보 세 요.사실은 xml 로 쓴 것 입 니 다.두 개의 속성 을 추가 해서 설정 하면 됩 니 다.하 나 는 style 이 고 다른 하 나 는 background 입 니 다.

<ProgressBar
android:id=”@+id/pb_progressbar”
style=”@style/StyleProgressBarMini”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_margin=”30dp”
android:background=”@drawable/shape_progressbar_bg”
android:max=”100″
android:progress=”50″ />
스타일 부터 볼 게 요.

<style name=”StyleProgressBarMini” parent=”@android:style/Widget.ProgressBar.Horizontal”>
<item name=”android:maxHeight”>50dip</item>
<item name=”android:minHeight”>10dip</item>
<item name=”android:indeterminateOnly”>false</item>
<item name=”android:indeterminateDrawable”>@android:drawable/progress_indeterminate_horizontal</item>
<item name=”android:progressDrawable”>@drawable/shape_progressbar_mini</item>
</style>
이 곳 의 progress Drawable 은 그림 이 아 닌 사용자 정의 drawable 을 참조 합 니 다.
shape_progressbar_mini.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<layer-list xmlns:android=”http://schemas.android.com/apk/res/android” >
<!C    C>
<item android:id=”@android:id/background”>
<shape>
<corners android:radius=”5dip” />
<gradient
android:angle=”270″
android:centerY=”0.75″
android:endColor=”#FFFFFF”
android:startColor=”#FFFFFF” />
</shape>
</item>
<item android:id=”@android:id/secondaryProgress”>
<clip>
<shape>
<corners android:radius=”0dip” />
<gradient
android:angle=”270″
android:centerY=”0.75″
android:endColor=”#df0024″
android:startColor=”#df0024″ />
</shape>
</clip>
</item>
<item android:id=”@android:id/progress”>
<clip>
<shape>
<corners android:radius=”5dip” />
<gradient
android:angle=”270″
android:centerY=”0.75″
android:endColor=”#de42ec”
android:startColor=”#de42ec” />
</shape>
</clip>
</item>
</layer-list>
다시 shapeprogressbar_bg.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<shape xmlns:android=”http://schemas.android.com/apk/res/android”
android:shape=”rectangle” >
<!C         C>
<solid android:color=”#cecece” />
<!C              C>
<!C android:radius       C>
<corners android:radius=”90dp” />
<!C
padding:     C>
<padding
android:bottom=”1dp”
android:left=”1dp”
android:right=”1dp”
android:top=”1dp” />
</shape>
이렇게 예 쁜 스 트 라 이 프 진 도 를 만 들 었 습 니 다.shapeprogressbar_bg.xml 에서 테두리 가 채 워 진 색 은 좋 은 방법 입 니 다.진도 바 의 테 두 리 를 추가 하 였 습 니 다.또한 진도 조 의 네 각 이 모두 원형 이기 위해 이 속성를 사 용 했 습 니 다.
됐어,이 럴 때 기분 좋게 물 한잔 하 러 가자.
2.원형 진도 조.또 하 나 는 원형 진도 줄 로 진행 중 임 을 나타 낸다.
작은 그림 2 장 보 겠 습 니 다.


첫 번 째 장 을 보고 코드 를 분석 하고 사용자 정의 view 로 pop 으로 만 들 었 습 니 다.LoadingDialog.java

public class LoadingDialog {
private Context context;
private PopupWindow popupDialog;
private LayoutInflater layoutInflater;
private RelativeLayout layout;
private RelativeLayout layout_bg;
private View circleView;
private RotateAnimation rotateAnim;
private AlphaAnimation alphaAnim_in;
private AlphaAnimation alphaAnim_out;
public LoadingDialog(Context context) {
layoutInflater = LayoutInflater.from(context);
this.context = context;
}
private void initAnim() {
rotateAnim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(2000);
rotateAnim.setRepeatMode(Animation.RESTART);
rotateAnim.setRepeatCount(-1);
rotateAnim.setInterpolator(new LinearInterpolator());
alphaAnim_in = new AlphaAnimation(0f, 1f);
alphaAnim_in.setFillAfter(true);
alphaAnim_in.setDuration(200);
alphaAnim_in.setInterpolator(new LinearInterpolator());
alphaAnim_out = new AlphaAnimation(1f, 0f);
alphaAnim_out.setFillAfter(true);
alphaAnim_out.setDuration(100);
alphaAnim_out.setInterpolator(new LinearInterpolator());
alphaAnim_out.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
dismiss();
}
});
}
/**
*       
* @return
*/
public boolean isShowing() {
if (popupDialog != null && popupDialog.isShowing()) {
return true;
}
return false;
}
/**
*   
*/
public void show() {
dismiss();
initAnim();
layout = (RelativeLayout) layoutInflater.inflate(R.layout.view_loadingdialog, null);
circleView = (View) layout.findViewById(R.id.loading_dialog);
layout_bg = (RelativeLayout) layout.findViewById(R.id.bgLayout);
popupDialog = new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
View parentView = ((Activity) context).getWindow().findViewById(Window.ID_ANDROID_CONTENT);
popupDialog.showAtLocation(parentView, Gravity.CENTER, 0, 0);
layout_bg.startAnimation(alphaAnim_in);
circleView.startAnimation(rotateAnim);
}
/**
*   
*/
public void dismiss() {
if (popupDialog != null && popupDialog.isShowing()) {
layout_bg.clearAnimation();
circleView.clearAnimation();
popupDialog.dismiss();
}
}
}
여 기 는 view 를 인 용 했 습 니 다.loadingdialog.xml,전체 페이지 의 배경 과 loading 상자 가 되 었 습 니 다.
view_loadingdialog.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent” >
<RelativeLayout
android:id=”@+id/bgLayout”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background=”#66000000″ >
<View
android:id=”@+id/loading_dialog”
android:layout_width=”48dp”
android:layout_height=”48dp”
android:layout_centerInParent=”true”
android:background=”@drawable/shape_loading_dialog” />
</RelativeLayout>
</RelativeLayout>
이 shape 다시 봐loading_dialog.xml,회전 하 는 원형 을 그립 니 다.그림 을 사용 하지 않 아 도 좋 습 니 다.

<?xml version=”1.0″ encoding=”utf-8″?>
<shape xmlns:android=”http://schemas.android.com/apk/res/android”
android:shape=”oval” >
<stroke
android:width=”3dp”
android:dashWidth=”2dp”
android:dashGap=”3dp”
android:color=”#fff”/>
<gradient
android:startColor=”#00ffffff”
android:endColor=”#00ffffff”
android:angle=”180″/>
</shape>
이렇게 첫 번 째 원형 진도 조 를 이 루 었 다.
그러나 색깔 이 있 는 원형 진도 줄 을 만 들 거나 색깔 이 있 는 것 을 나중에 생각해 보 니 그림 을 추가 해서 실현 하 는 것 이 좋 겠 다.
LoadingImgDialog.java

public class LoadingImgDialog {
private Context context;
private PopupWindow popupDialog;
private LayoutInflater layoutInflater;
private RelativeLayout layout;
private RelativeLayout layout_bg;
private int residBg;
private View loading_dialog;
/**           ,         **/
private RotateAnimation rotateAnim;
/**         **/
private AlphaAnimation alphaAnim_in;
private AlphaAnimation alphaAnim_out;
public LoadingImgDialog(Context context, int residBg) {
layoutInflater = LayoutInflater.from(context);
this.residBg = residBg;
this.context = context;
}
private void initAnim() {
rotateAnim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(2000);
rotateAnim.setRepeatMode(Animation.RESTART);
rotateAnim.setRepeatCount(-1);
rotateAnim.setInterpolator(new LinearInterpolator());
alphaAnim_in = new AlphaAnimation(0f, 1f);
alphaAnim_in.setFillAfter(true);
alphaAnim_in.setDuration(200);
alphaAnim_in.setInterpolator(new LinearInterpolator());
alphaAnim_out = new AlphaAnimation(1f, 0f);
alphaAnim_out.setFillAfter(true);
alphaAnim_out.setDuration(100);
alphaAnim_out.setInterpolator(new LinearInterpolator());
/**     ,     ,  LoadingColorDialog **/
alphaAnim_out.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
dismiss();
}
});
}
/**
*       
* @return
*/
public boolean isShowing() {
if (popupDialog != null && popupDialog.isShowing()) {
return true;
}
return false;
}
/**
*   
*/
public void show() {
dismiss();
initAnim();
layout = (RelativeLayout) layoutInflater.inflate(R.layout.view_loadingcolordialog, null);
loading_dialog = (View) layout.findViewById(R.id.loading_dialog);
loading_dialog.setBackgroundResource(residBg);
layout_bg = (RelativeLayout) layout.findViewById(R.id.bgLayout);
popupDialog = new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
View parentView = ((Activity) context).getWindow().findViewById(Window.ID_ANDROID_CONTENT);
popupDialog.showAtLocation(parentView, Gravity.CENTER, 0, 0);
layout_bg.startAnimation(alphaAnim_in);
loading_dialog.startAnimation(rotateAnim);
}
/**
*   
*/
public void dismiss() {
if (popupDialog != null && popupDialog.isShowing()) {
layout_bg.clearAnimation();
loading_dialog.clearAnimation();
popupDialog.dismiss();
}
}
}
사실은 한 곳 을 수정 하고 residBg 를 추가 하여 이미지 자원 으로 원형 진도 조 의 작은 부분 배경 을 설정 한 것 입 니 다.
코드 를 조금 만 수정 하고 그림 을 바 꾸 면 또 다른 원형 진도 가 됩 니 다.재 미 있 죠?
loadingColorDialog = new LoadingImgDialog(this, R.drawable.img_loading);
loadingColorDialog2 = new LoadingImgDialog(this, R.drawable.img_loading2);
전체 화면 효과 도 를 보 여 주세요.코드 를 조금 만 수정 하고 그림 을 바 꿔 주세요.

마지막 으로 MainActivity.java 에 게 보 여 주세요.

public class MainActivity extends Activity implements OnClickListener {
Button bt_loading_dialog;
Button bt_color_loading_dialog;
Button bt_color_loading_dialog2;
LoadingDialog loadingDialog;
LoadingImgDialog loadingColorDialog;
LoadingImgDialog loadingColorDialog2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
bt_loading_dialog = (Button) findViewById(R.id.bt_loading_dialog);
bt_loading_dialog.setOnClickListener(this);
bt_color_loading_dialog = (Button) findViewById(R.id.bt_loading_img_dialog);
bt_color_loading_dialog.setOnClickListener(this);
bt_color_loading_dialog2 = (Button) findViewById(R.id.bt_loading_img_dialog2);
bt_color_loading_dialog2.setOnClickListener(this);
loadingDialog = new LoadingDialog(this);
loadingColorDialog = new LoadingImgDialog(this, R.drawable.img_loading);
loadingColorDialog2 = new LoadingImgDialog(this, R.drawable.img_loading2);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.bt_loading_dialog:
loadingDialog.show();
break;
case R.id.bt_loading_img_dialog:
loadingColorDialog.show();
break;
case R.id.bt_loading_img_dialog2:
loadingColorDialog2.show();
break;
default:
break;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
loadingColorDialog.dismiss();
}
@Override
public void onBackPressed() {
if (loadingDialog.isShowing()) {
loadingDialog.dismiss();
} else if (loadingColorDialog.isShowing()){
loadingColorDialog.dismiss();
} else if (loadingColorDialog2.isShowing()){
loadingColorDialog2.dismiss();
} else {
finish();
}
}
}

이상 은 안 드 로 이 드 진도 항목 에 대한 자 료 를 정리 하고 후속 적 으로 관련 자 료 를 계속 보충 하 는 것 입 니 다.본 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기