java 双手柄滑块安卓
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5606121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Double handled slider android
提问by Ovidiu Birgu
I was wondering if anyone had some code, or knew of a place that has code for creating a double handled slider. Example :
我想知道是否有人有一些代码,或者知道一个地方有创建双处理滑块的代码。例子 :
I am looking to do something similar using a double slider to search for a range of ages on a time array , like in the photo
我正在寻找使用双滑块做类似的事情来搜索时间数组上的年龄范围,就像照片一样
Thanks in advance
提前致谢
采纳答案by Ovidiu Birgu
I managed to build it myself... the idea I followed was different from the answers above. I created some items that can be dragged on the screen with the finger, and I fixed the Y position so it can only move from left to right. After that, I generated rectangles that signify the progress (between knobs and outside them). The good thing about this technique is that you can easily customize the slider to be vertical or horizontal, or if you want to put a custom picture in the background. The source is in the link below, and if anyone has any questions please ask. link: eclipse project
我设法自己构建它......我遵循的想法与上面的答案不同。我创建了一些可以用手指在屏幕上拖动的项目,并固定了 Y 位置,使其只能从左向右移动。之后,我生成了表示进度的矩形(在旋钮之间和在它们外面)。这种技术的好处是您可以轻松地将滑块自定义为垂直或水平,或者如果您想在背景中放置自定义图片。来源在下面的链接中,如果有人有任何问题,请提问。链接:eclipse项目
回答by GaryGeo
Have you seen the range-seek-bar. It looks like it would work perfectly.!
你见过range-seek-bar吗?看起来它会完美地工作。!
回答by dst
You could try and extend the AbsSeekBarand have a look at the single-thumbed-SeekBarhow it works.
您可以尝试扩展AbsSeekBar并查看单拇指SeekBar 的工作原理。
回答by BoffinBrain
I have looked through the entire Widgets packageand incredibly, the ADT doesn't have any slider control! This obviously puts you at a serious disadvantage since there is nothing already implemented for you to extend or modify.
我浏览了整个Widgets 包,令人难以置信的是,ADT 没有任何滑块控件!这显然使您处于严重的劣势,因为您还没有实现任何可以扩展或修改的内容。
However, there is this guide on hacking together a custom slider component out of a ProgressBarcomponent. This might be your solution. The author overrides the onTouchEvent
method to set the progress bar's value according to the touch coordinates. Very clever. However, since a progress bar can only show one value, it's only possible to show the lower or upper bound using a single progress bar.
但是,有一个关于从 ProgressBar组件中破解自定义滑块组件的指南。这可能是您的解决方案。作者重写了onTouchEvent
根据触摸坐标设置进度条值的方法。非常聪明。但是,由于进度条只能显示一个值,因此只能使用单个进度条显示下限或上限。
My suggestion is to create a compound component which has one progress bar that is always at 0%, and another progress bar which is always at 100%. The second bar is overlaid on top of the first one, and its coordinates and width set so its left edge represents the lower bound (x), and the right edge shows the upper bound (x + width). Your onTouchEvent
will detect whether the touch coordinates are closer to the lower or upper bound, and then start adjusting that bound until released. When the bounds change, you simply reposition and resize the second bar. Provided you can position components absolutely and on top of other components, this should look great!
我的建议是创建一个复合组件,其中一个进度条始终为 0%,另一个进度条始终为 100%。第二个条形覆盖在第一个条形的顶部,其坐标和宽度设置为左边缘代表下限 (x),右边缘显示上限 (x + 宽度)。您onTouchEvent
将检测触摸坐标是否更接近下限或上限,然后开始调整该边界直到释放。当边界发生变化时,您只需重新定位和调整第二个栏的大小。如果您可以将组件绝对放置在其他组件之上,这看起来应该很棒!