2014-12-09 24 views
0

我创造了我的应用项目覆盖对话框的防止Android的搜索栏,这是它的外观:的进展变化绘制多个大拇指

overlay dialog

的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仅被分配一次。代码/布局中是否有任何错误,我错过了并导致了这种奇怪的视觉行为?

谢谢!

+0

https://www.informaticscentre.co.uk/blog/implementing-a-seekbar-with-stepped-intervals-in-android – 2014-12-09 11:49:58

+1

对不起,你没有理解我的问题。我不是试图实现这种行为,我试图摆脱默认SeekBar这个。我不明白,为什么它不像正常工作。 – 2014-12-09 11:53:46

+0

@insomnium_当进度发生变化时,你所做的事情是什么?['onProgressChanged()'] – 2014-12-09 12:54:51

回答

0

我觉得你的问题不是多大拇指,但多个SeekBars,多alertDialogLayout而且每一个都有一个SeekBar,或创建的每一个创建一个alertDialogLayout多个对象,因此,在首先确保你发起alertDialogLayout只有一次,也是你开始SeekBar只有一次,也请确保你是不是(一些如何)启动alertDialogLayoutSeekBar搜索栏进度变化,并随时检验所有这一切,只是改变alertDialogLayoutSeekBar声明static,看看这种奇怪的行为是否消失。

+0

'SeekBar'和'alertDialogLayout'从一开始就是'private static'。我刚刚尝试删除静态关键字 - 无需更改。 – 2014-12-10 11:31:11

+0

@insomnium_很好,但是没有办法拥有这么多的拇指,我认为这种行为的唯一方法就是创建一个seekbar的多个seekbars或多个东西。 – 2014-12-10 11:33:27

+0

@insomnium_和一个很好的方法来发现发生了什么,重写'onProgressChanged()'方法[只是在控制台中打印任何东西],以确保它们是由于搜索或不搜索而产生的。 – 2014-12-10 11:41:34