zoukankan      html  css  js  c++  java
  • Android—进度条

    layout文件:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     xmlns:tools="http://schemas.android.com/tools"
     4     android:layout_width="match_parent"
     5     android:layout_height="match_parent"
     6     android:paddingBottom="@dimen/activity_vertical_margin"
     7     android:paddingLeft="@dimen/activity_horizontal_margin"
     8     android:paddingRight="@dimen/activity_horizontal_margin"
     9     android:paddingTop="@dimen/activity_vertical_margin"
    10     tools:context="com.hanqi.testapp2.TestActivity4"
    11     android:orientation="vertical">
    12 
    13     <ProgressBar
    14         android:layout_width="match_parent"
    15         android:layout_height="wrap_content"
    16         style="?android:attr/progressBarStyleHorizontal"
    17         android:progress="0"
    18         android:secondaryProgress="0"
    19         android:max="80"
    20         android:id="@+id/pb_1"/>
    21     <ProgressBar
    22         android:layout_width="match_parent"
    23         android:layout_height="wrap_content"
    24         style="?android:attr/progressBarStyleLarge"
    25         android:id="@+id/pb_2"/>
    26     <SeekBar
    27         android:layout_width="match_parent"
    28         android:layout_height="wrap_content"
    29         android:progress="0"
    30         android:max="80"
    31         android:secondaryProgress="0"
    32         android:id="@+id/se_1"/>
    33     <RatingBar
    34         android:layout_width="wrap_content"
    35         android:layout_height="wrap_content"
    36         android:numStars="5"
    37         android:rating="3.5"
    38         android:isIndicator="true"/>
    39 </LinearLayout>

    java类代码:

     1 package com.hanqi.testapp2;
     2 
     3 import android.app.AlertDialog;
     4 import android.os.Bundle;
     5 import android.support.v7.app.AppCompatActivity;
     6 import android.util.Log;
     7 import android.view.View;
     8 import android.widget.ProgressBar;
     9 import android.widget.SeekBar;
    10 
    11 public class TestActivity4 extends AppCompatActivity {
    12 
    13     SeekBar se_1;
    14     ProgressBar pb_1;
    15     ProgressBar pb_2;
    16     @Override
    17     protected void onCreate(Bundle savedInstanceState) {
    18         super.onCreate(savedInstanceState);
    19         setContentView(R.layout.activity_test4);
    20         se_1 = (SeekBar)findViewById(R.id.se_1);
    21         pb_1 = (ProgressBar)findViewById(R.id.pb_1);
    22         pb_2 = (ProgressBar)findViewById(R.id.pb_2);
    23 
    24         AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    25 
    26         se_1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    27             //进度变化触发
    28             @Override
    29             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    30                 //设置进度条1的进度值
    31                 pb_1.setProgress(progress);
    32                 //判断是否达到最大值
    33                 if(progress ==se_1.getMax())
    34                 {
    35                     pb_2.setVisibility(View.INVISIBLE);//不显示但位置还保留
    36                 }
    37                 else
    38                 {
    39                     pb_2.setVisibility(View.VISIBLE);
    40                 }
    41                 //只要progress变化就会触发
    42                 //Toast.makeText(TestActivity4.this, "当前进度 = "+progress, Toast.LENGTH_SHORT).show();
    43             }
    44 
    45             @Override
    46             public void onStartTrackingTouch(SeekBar seekBar) {
    47                 Log.e("TAG","进度条开始拖动");
    48             }
    49 
    50             @Override
    51             public void onStopTrackingTouch(SeekBar seekBar) {
    52                 Log.e("TAG","进度条停止拖动");
    53             }
    54         });
    55     }
    56 }

    效果为:

  • 相关阅读:
    krpano--控制热点跳转到场景的指定视角
    bzoj 4237: 稻草人 -- CDQ分治
    bzoj 4176: Lucas的数论 -- 杜教筛,莫比乌斯反演
    bzoj 3545/3551: [ONTAK2010]Peaks -- 主席树,最小生成树,倍增
    bzoj 4627: [BeiJing2016]回转寿司 -- 权值线段树
    bzoj 1901: Zju2112 Dynamic Rankings -- 主席树,树状数组,哈希
    bzoj 3252: 攻略 -- 长链剖分+贪心
    bzoj 5055: 膜法师 -- 树状数组
    bzoj 1006: [HNOI2008]神奇的国度 -- 弦图(最大势算法)
    bzoj 1176: [Balkan2007]Mokia&&2683: 简单题 -- cdq分治
  • 原文地址:https://www.cnblogs.com/hanazawalove/p/5478789.html
Copyright © 2011-2022 走看看