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

首頁 > 系統 > Android > 正文

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

2019-12-12 01:14:20
字體:
來源:轉載
供稿:網友

需求場景:當我們在使用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); }}

效果圖:

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麻栗坡县| 天长市| 安顺市| 孝昌县| 山阴县| 遂宁市| 东台市| 灯塔市| 永登县| 延边| 嘉善县| 灵山县| 秭归县| 赣州市| 蚌埠市| 涞水县| 江孜县| 柳河县| 兰坪| 江源县| 南昌县| 习水县| 玛沁县| 台南县| 嘉善县| 剑阁县| 吐鲁番市| 视频| 法库县| 鄂伦春自治旗| 龙州县| 玉门市| 邵东县| 扶余县| 凤庆县| 九台市| 江城| 大英县| 遂溪县| 临高县| 建德市|