美文网首页
Android进度条

Android进度条

作者: Amy木婉清 | 来源:发表于2020-08-25 08:36 被阅读0次

Android进度条

不同的进度条显示结果:


image.png

demo xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".util.ProgressActivity"
    android:padding="15dp">
    <ProgressBar
        android:id="@+id/pb1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <ProgressBar
        android:id="@+id/pb2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar"
        android:layout_marginTop="10dp"/>
    <!--  android:max="100"android:progress="10"
       总共为100,目前到10 android:secondaryProgress="30"
       第二个进度为30-->
    <ProgressBar
        android:id="@+id/pb3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_marginTop="10dp"
        android:max="100"
        android:progress="10"
        android:secondaryProgress="30"/>
    <ProgressBar
        android:id="@+id/pb4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.Material.ProgressBar.Horizontal"
        android:layout_marginTop="10dp"
        android:max="100"
        android:progress="10"
        android:secondaryProgress="30"/>
</LinearLayout>

二.模拟进度条加载过程:
运行展示图:


image.png image.png

xml代码:

   <Button
        android:id="@+id/btn_start"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="模拟进度"
        android:layout_marginTop="10dp"/>

Activity代码:

package com.example.lineralayout.util;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.lineralayout.R;

public class ProgressActivity extends AppCompatActivity {
    private ProgressBar mPb3;
    private Button mBtnStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress);
        mPb3 = findViewById(R.id.pb3);
        mBtnStart = findViewById(R.id.btn_start);
        mBtnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                handler.sendEmptyMessage(0);
            }
        });
    }
    Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(mPb3.getProgress() < 100){
                handler.postDelayed(runnable,500);
            }else{
               ToastUtil.showMsg(ProgressActivity.this,"加载完成");
            }

        }
    };
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            mPb3.setProgress(mPb3.getProgress()+5);
            handler.sendEmptyMessage(0);
        }
    };
}

三.自定义加载图片


image.png

自定义drawable资源:

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/progress"
    android:pivotX="50%"
    android:pivotY="50%">
</animated-rotate>

应用:

    <ProgressBar
        android:id="@+id/pb5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar"
        android:indeterminateDrawable="@drawable/bg_progress"
        android:layout_marginTop="10dp"/>

相关文章

  • 控件 - ProgressBar

    ProgressBar 进度条 进度条 属性 android:id:ID,唯一标识符。 android:layou...

  • ProgressBar进度条

    SeekBar :搜寻进度条RatingBar:评价进度条 style="?android:attr/progre...

  • Android进度条

    Android进度条 不同的进度条显示结果: demo xml代码: 二.模拟进度条加载过程:运行展示图: xml...

  • Android之进度条控件和常用资源分类总结

    1 基本UI(二) 1.1进度条 1.1.1 【 常用属性: style进度条样式 Android:max进度...

  • SeekBar

    Android-SeekBar进度条的使用Android控件与布局——基础控件SeekBar

  • 自定义进度条

    1.自定义进度条UI 2.进度条动效 Animate ProgressBar update in Android

  • 进度条使用

    目录 ProgressBar(进度条) ProgressBar是Android下的进度条,也是为数不多的直接继承于...

  • ProgressBar的美化

    横向进度条 style="?android:attr/progressBarStyleHorizontal"制定进...

  • SeekBar自定义样式最优实现

    1. 布局文件 android:thumb为滑块的样式 android:progressDrawable为进度条样...

  • Android自定义圆形进度条学习

    Android中圆形进度条的应用还是挺多的,最近学习实现了圆形进度条。 思路 要实现圆形进度条, 首先要画灰色背景...

网友评论

      本文标题:Android进度条

      本文链接:https://www.haomeiwen.com/subject/uivnjktx.html