Android Seekbar 有两个拇指

发布于 2024-11-03 11:33:20 字数 195 浏览 1 评论 0原文

这个问题的变体可以在互联网上找到,但没有答案。

我想要一个带有两个拇指范围选择的搜索栏。我愿意自己编程,但缺乏 Android 经验。有人可以给我一些关于从哪里开始的指示吗?我的意思是,我知道我必须扩展一些东西(可能是进度条),但是我应该如何去做呢?我真的必须重新创建标准搜索栏的所有功能吗?还是有更简单的方法?

当然,也欢迎完整的解决方案;)

Variations of this question can be found all over the internet but not an answer.

I want a seekbar with two-thumb range selection. I'm willing to program this myself but I lack experience with Android. Could someone give me some pointers on where to start. I mean, I know I will have to extend something (ProgressBar probably), but how should I go about to do that? Do I really have to recreate all the functionality of a standard seekbar, or is there an easier way?

Complete solutions are also welcome of course ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

人│生佛魔见 2024-11-10 11:33:20

我也一直在找这个,没有结果。所以我制作了一个新的小部件,请随意使用它: https://github.com/ anothem/android-range-seek-bar

RangeSeekBar 的屏幕截图

I too was looking for this, to no avail. So I made a new widget, feel free to use it: https://github.com/anothem/android-range-seek-bar

Screenshot of RangeSeekBar

倾`听者〃 2024-11-10 11:33:20

“我也在寻找这个,但没有成功。所以我制作了一个新的小部件,请随意使用它: https://code.google.com/p/range-seek-bar/

Stephan 链接的这个示例效果非常好!
然而,用户必须按下任意拇指才能获得响应。我希望如果用户按下该栏,最近的拇指就会移动到该位置并像平常一样工作。

我在示例代码中实现了这一点,如下所示:

private final Thumb getClosestThumb(float touchX)

{
    double xValue = screenToNormalized(touchX);        
    return (Math.abs(xValue - normalizedMinValue) < Math.abs(xValue - normalizedMaxValue)) ? Thumb.MIN : Thumb.MAX;
}

在“public boolean onTouchEvent(MotionEvent event)”中,

if(pressedThumb == null),
   pressedThumb = getClosestThumb(mDownMotionX);

"I too was looking for this, to no avail. So I made a new widget, feel free to use it: https://code.google.com/p/range-seek-bar/"

This example Stephan linked works great!
However, the user has to press any of the thumbs to get a respons. I wanted that if the user pressed the bar, the closest thumb would move to that position and work like normal.

I implemented this in the example code like this:

private final Thumb getClosestThumb(float touchX)

{
    double xValue = screenToNormalized(touchX);        
    return (Math.abs(xValue - normalizedMinValue) < Math.abs(xValue - normalizedMaxValue)) ? Thumb.MIN : Thumb.MAX;
}

And in the "public boolean onTouchEvent(MotionEvent event)",

if(pressedThumb == null),
   pressedThumb = getClosestThumb(mDownMotionX);
开始看清了 2024-11-10 11:33:20

带有左右图标的窗口搜索栏。
可预设最小窗口大小和自动防交叉。

windowed-seek-bar 的屏幕截图

Mercurial 存储库位于 https://bitbucket.org/nimbusgb/windowed-seek-bar

A windowed seek bar with left and right icons.
Presettable minimum window size and automatic anti crossover.

Screenshot of windowed-seek-bar

Mercurial repository at https://bitbucket.org/nimbusgb/windowed-seek-bar

找回味觉 2024-11-10 11:33:20

我使用了 anothem/android-range-seek-bar 库

https://github.com /anothem/android-range-seek-bar

在 xml 中

<org.florescu.android.rangeseekbar.RangeSeekBar
            android:id="@+id/pricebar_with_label"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            rsb:absoluteMinValue="20"
            rsb:absoluteMaxValue="150"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            />

在此处输入图像描述

I have used the anothem/android-range-seek-bar library

https://github.com/anothem/android-range-seek-bar

In xml

<org.florescu.android.rangeseekbar.RangeSeekBar
            android:id="@+id/pricebar_with_label"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            rsb:absoluteMinValue="20"
            rsb:absoluteMaxValue="150"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            />

enter image description here

别在捏我脸啦 2024-11-10 11:33:20

如果您正在使用任何材料组件,例如:Snackbar、BottomNavigationView 等,则不必使用其他第 3 方库。

材质库还附带 RangeSlider,它可以用于选择一个值范围。

材质库 - 实现“com.google.android.material:material:latestVersion”

Incase you are using any of the material components such as: Snackbar, BottomNavigationView etc. you don't have to use another 3rd party library.

The material library also ships with RangeSlider which can be used to select a range of values.

Material library - implementation 'com.google.android.material:material:latestVersion'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文