国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android使用動畫設置ProgressBar進度的方法

2019-10-22 18:16:21
字體:
來源:轉載
供稿:網友

需求場景:當我們在使用ProgressBar的時候,希望有進度加載的效果,此時我們傳統的做法是使用Thread線程來實現,下面我們用屬性動畫來實現,簡單粗暴。。哈哈哈

布局文件:

<?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" tools:context="com.yhx.app.progressbardemo.MainActivity"> <ProgressBar  android:layout_marginTop="20dp"  android:id="@+id/bar"  android:layout_width="match_parent"  android:layout_height="8dp"  style="?android:attr/progressBarStyleHorizontal"  android:progress="10"  android:max="100"> </ProgressBar> <Button  android:hint="開始"  android:onClick="show"  android:layout_marginTop="50dp"  android:layout_width="match_parent"  android:layout_height="50dp"/> <TextView  android:id="@+id/tv_bar"  android:layout_marginTop="20dp"  android:layout_width="100dp"  android:text="0"  android:gravity="center"  android:textSize="38dp"  android:layout_gravity="center"  android:layout_height="100dp"/> <Button  android:hint="開始"  android:onClick="tvshow"  android:layout_marginTop="50dp"  android:layout_width="match_parent"  android:layout_height="50dp"/></LinearLayout>

Activity:

public class MainActivity extends AppCompatActivity { private ProgressBar mProgressBar; TextView mtv_bar; @Override protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.activity_main);  mProgressBar = (ProgressBar) findViewById(R.id.bar);  mtv_bar = (TextView) findViewById(R.id.tv_bar);  setAnimation(mProgressBar, 100); } private void setAnimation(final ProgressBar view, final int mProgressBar) {  ValueAnimator animator = ValueAnimator.ofInt(0, mProgressBar).setDuration(5000);  animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {   @Override   public void onAnimationUpdate(ValueAnimator valueAnimator) {    view.setProgress((int) valueAnimator.getAnimatedValue());   }  });  animator.start(); } private void setTvAnimation(final TextView view, final int mProgressBar) {  ValueAnimator animator = ValueAnimator.ofInt(0, mProgressBar).setDuration(5000);  animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {   @Override   public void onAnimationUpdate(ValueAnimator valueAnimator) {    view.setText(String.valueOf(valueAnimator.getAnimatedValue()));   }  });  animator.start(); } public void show(View view) {  setAnimation(mProgressBar, 100); } public void tvshow(View view){  setTvAnimation(mtv_bar,240); }}

效果圖:

Android,ProgressBar,進度

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 庆阳市| 桂平市| 嘉义县| 南通市| 德清县| 富锦市| 武定县| 肃北| 浦东新区| 泸西县| 河源市| 余江县| 夏津县| 滨海县| 托克逊县| 开远市| 莲花县| 舒兰市| 荆州市| 固安县| 商丘市| 乌兰察布市| 江阴市| 漳州市| 湘阴县| 麻城市| 湄潭县| 云龙县| 兴文县| 谷城县| 东乡| 仙桃市| 霸州市| 衡阳市| 株洲市| 定日县| 阜新市| 辽中县| 彭泽县| 方正县| 定远县|