我创造了我的应用项目覆盖对话框的防止Android的搜索栏,这是它的外观:的进展变化绘制多个大拇指
的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/ipTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white" />
<SeekBar
android:id="@+id/volumeSeekBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:focusable="false"
android:indeterminate="false"
android:max="63"
android:mirrorForRtl="false" />
<TextView
android:id="@+id/portTv"
style="@android:style/Theme.Dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="63"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white" />
</LinearLayout>
的代码:
if (alertDialogLayout == null) {
alertDialogLayout = View.inflate(getApplicationContext(), R.layout.volume_dialog, null);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
WindowManager.LayoutParams wmlp = new LayoutParams();
wmlp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
wmlp.width = dm.widthPixels/5;
wmlp.height = LayoutParams.WRAP_CONTENT;
wmlp.y += 10;
wmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
wmlp.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL;
wm.addView(alertDialogLayout, wmlp);
}
if (volumeBar == null) {
volumeBar = (SeekBar) alertDialogLayout.findViewById(R.id.volumeSeekBar);
volumeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//Do some stuff
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});
}
为什么SeekBar添加了多个拇指?当我拖动它时,会出现更多的拇指,直到它们完全充满为止。我检查过 - OnSeekBarChangeListener
仅被分配一次。代码/布局中是否有任何错误,我错过了并导致了这种奇怪的视觉行为?
谢谢!
https://www.informaticscentre.co.uk/blog/implementing-a-seekbar-with-stepped-intervals-in-android – 2014-12-09 11:49:58
对不起,你没有理解我的问题。我不是试图实现这种行为,我试图摆脱默认SeekBar这个。我不明白,为什么它不像正常工作。 – 2014-12-09 11:53:46
@insomnium_当进度发生变化时,你所做的事情是什么?['onProgressChanged()'] – 2014-12-09 12:54:51