gpt4 book ai didi

android - 动画后 ProgressBar 未正确更新

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:21 25 4
gpt4 key购买 nike

我有一个带有 ProgressBar 的布局(实际上它是一个 SeekBar,但同样的问题发生在 ProgressBar 上)。在我开始为整个布局制作动画并将其向下翻译之前,它工作正常。在动画期间,ProgressBar 继续按预期工作,但是当动画完成时(我使用 Animation.setFillAfter(true) 将布局卡住在动画的最终位置),ProgressBar 停止正确更新,而只是一条小线在进度条的顶部保持更新,而进度条的底部保持卡住(它是一个水平进度条)。

一些代码:带有进度条的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left">
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/progressbar_Horizontal"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
/>

这里是我定义动画的地方:

Animation a = AnimationUtils.loadAnimation(this, R.anim.translate_down);
a.setFillAfter(true);

这是我在整个布局上开始动画的地方:

View vv = p.findViewById(R.id.video_buttons);
vv.startAnimation(anim);

最佳答案

我的第一个想法是您可能无意中使用了“android:secondaryProgress”属性。

除此之外,如果您在单独的线程中运行它,请确保您使用的是以下内容:

activity.runOnUiThread(new Runnable() //
{
public void run() //
{
int newProgressVal = Integer
.parseInt((String) syncProgressNumber.getText()) + 1;
syncProgress.incrementProgressBy(1);
syncProgressNumber.setText(String
.valueOf(newProgressVal));
}
});

UI 线程不是线程安全的,因此您不能从其他线程更新 UI。

希望这对您有所帮助!

关于android - 动画后 ProgressBar 未正确更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5636516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com