7 android toggle seekbar progress-bar
我正试图SeekBar在两种模式之间切换以显示流媒体的状态.
我已经确定android:indeterminate在XML中定义标记时显示正确的图形:
<SeekBar
android:id="@+id/seekBar1"
android:indeterminate="false"
android:progressDrawable="@android:drawable/progress_horizontal"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:indeterminateBehavior="cycle"
android:indeterminateOnly="false"
android:progress="33"
android:secondaryProgress="66"
android:layout_height="wrap_content"
android:layout_width="match_parent"></SeekBar>
Run Code Online (Sandbox Code Playgroud)

问题是,当试图通过调用切换时setIndeterminate(true),drawable似乎没有正确改变.在indeterminate-> determinate的情况下,动画停止,并且从determinate-> indeterminate,没有任何反应.
我究竟做错了什么?
SeekBar onSizeChanged() 仅初始化当前选定的背景可绘制对象,并在初始化 SeekBar 时调用一次。所以修复可能是:
public class CorrectedSeekBar extends SeekBar {
public CorrectedSeekBar(Context context) {
super(context);
}
public CorrectedSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CorrectedSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
boolean current = isIndeterminate();
setIndeterminate(!current);
super.onSizeChanged(w, h, oldw, oldh);
setIndeterminate(current);
super.onSizeChanged(w, h, oldw, oldh);
}
}
Run Code Online (Sandbox Code Playgroud)
并在布局xml中使用<yourpackage.CorrectedSeekBar ...
这看起来不太好,可能还有其他解决方法,但我认为这是主要问题(错误?)。
| 归档时间: |
|
| 查看次数: |
4893 次 |
| 最近记录: |