直播源码开发,使用动画设置ProgressBar进度
布局文件:
<?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);
}
}
以上就是 直播源码开发,使用动画设置ProgressBar进度,更多内容欢迎关注之后的文章
标签:动画,mProgressBar,layout,void,ProgressBar,源码,bar,android,ValueAnimator From: https://www.cnblogs.com/yunbaomengnan/p/17469103.html