Giter Site home page Giter Site logo

circlenumberprogressbar's Introduction

CircleNumberProgressBar

一个可以显示数字进度的圆形进度条

效果图

使用

设置布局文件和默认样式

  • 直接在布局文件中声明

      <com.zht.circlenumberprogressbar.widget.CircleNumberProgressBar
          android:id="@+id/cnpb_progress_second"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          app:cnpb_circle_radius="80dp"
          app:cnpb_reach_color="@color/colorAccent"
          app:cnpb_text_color="@color/colorAccent"
          app:cnpb_text_size="20sp" />
    
  • 在styles文件中设置

      <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
          <!-- Customize your theme here. -->
          ...
          <item name="styleCircleNumberProgressBar">@style/CircleNumberProgressBarTheme</item>
      </style>
    
      <style name="CircleNumberProgressBarTheme" parent="CircleNumberProgressBar.Style">
          <item name="cnpb_text_color">#FF303F9F</item>
      	...
      </style>
    

属性

	<declare-styleable name="CircleNumberProgressBar">
    
        <!-- 圆的半径 -->
        <attr name="cnpb_circle_radius" format="dimension"/>

        <!-- 进度条的宽度 -->
        <attr name="cnpb_bar_width" format="dimension" />
        
        <!-- 达到的进度颜色 -->
        <attr name="cnpb_reach_color" format="color" />
        
        <!-- 未达到的进度颜色 -->
        <attr name="cnpb_unreach_color" format="color" />
        
        <!-- 文字大小 -->
        <attr name="cnpb_text_size" format="dimension" />

        <!-- 文字颜色 -->
        <attr name="cnpb_text_color" format="color" />

        <!-- 文字是否显示 -->
        <attr name="cnpb_text_visibility" format="enum">
            <enum name="invisible" value="0"/>
            <enum name="visible" value="1"/>
        </attr>

        <!-- 单位 -->
        <attr name="cnpb_unit" format="string"/>

        <!-- 单位是否显示 -->
        <attr name="cnpb_unit_visibility" format="enum">
            <enum name="invisible" value="0"/>
            <enum name="visible" value="1"/>
        </attr>

    </declare-styleable>

Activity使用

	public class MainActivity extends AppCompatActivity {

    private CircleNumberProgressBar progressBarFirst;

    private CircleNumberProgressBar progressBarSecond;

    private static final int PROGRESS_UPDATE = 1;

    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {

            int progress = progressBarFirst.getProgress();
            progress += 1;

            if (progress >= 100) {
                handler.removeMessages(PROGRESS_UPDATE);
            }

            progressBarFirst.setProgress(progress);
            handler.sendEmptyMessageDelayed(PROGRESS_UPDATE, 500);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBarFirst = (CircleNumberProgressBar) findViewById(R.id.cnpb_progress_first);
        progressBarSecond = (CircleNumberProgressBar) findViewById(R.id.cnpb_progress_second);

        handler.sendEmptyMessage(PROGRESS_UPDATE);
        progressBarSecond.setProgress(80);
//        progressBarFirst.setProgress(80);
    }
}

详细文章

CiecleNumberProgressBar的详细介绍可以查看文章CircleNumberProgressBar

circlenumberprogressbar's People

Contributors

alarmzeng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.