我遇到了一个奇怪的问题。在我的应用程序中,我有一个自定义 SeekBar
,其拇指有 2 个状态。当我单击 seekBar
时,它的拇指会变形,并且在几秒钟后恢复到正常状态。相应的 MediaPlayer
对象立即使用react,如下所示不出所料,这个问题只是一个视觉问题。快照来说明这一点:
正常行为:
当点击 seekBar
时:
我不知道这有什么问题。
搜索栏:
<SeekBar
android:id="@+id/seekBarMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:indeterminate="false"
android:maxHeight="3dp"
android:maxWidth="450dp"
android:minHeight="3dp"
android:paddingLeft="9dp"
android:paddingRight="9dp"
android:progressDrawable="@drawable/pb"
android:thumb="@drawable/thumb_state" />
用于拇指的可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/thumb_pressed" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="@drawable/thumb" android:state_pressed="false"/>
</selector>
OnTouchListener:
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.seekBarMain) {
if (mp.isPlaying()) {
int playPositionInMillisecconds = (mediaFileLengthInMilliseconds / 100)
* sb.getProgress();
mp.seekTo(playPositionInMillisecconds);
} else {
int playPositionInMillisecconds = (mediaFileLengthInMilliseconds / 100)
* sb.getProgress();
mp.start();
mp.seekTo(playPositionInMillisecconds);
btnPlay.setBackgroundResource(R.drawable.button_pause);
primarySeekBarProgressUpdater();
}
}
return false;
}
有什么想法为什么会发生这种情况吗?
最佳答案
好吧,我刚刚发现这个问题与 "thumb_pressed"
可绘制对象有关,它比正常状态下使用的可绘制对象大约大 25%。我无法真正解释这一点,但是将 "thumb_pressed"
可绘制对象修改为与 "thumb"
可绘制对象具有相同的大小可以解决该问题。
关于android - 单击seekBar 时seekBar 拇指会拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572424/