Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中制作双seekbar?_Android_Customization_Seekbar - Fatal编程技术网

如何在android中制作双seekbar?

如何在android中制作双seekbar?,android,customization,seekbar,Android,Customization,Seekbar,我正在构建一个android应用程序,用户通过seekbar选择最大值 我需要在同一seekbar上的另一个按钮,以便用户可以从特定的唯一seekbar中选择最大值和最小值 这是我的单搜索条代码- package com.ui.yogeshblogspot; public class CustomSeekBarExActivity extends Activity implements OnSeekBarChangeListener{ /** Called when the activity

我正在构建一个android应用程序,用户通过seekbar选择最大值

我需要在同一seekbar上的另一个按钮,以便用户可以从特定的唯一seekbar中选择最大值和最小值

这是我的单搜索条代码-

package com.ui.yogeshblogspot;

public class CustomSeekBarExActivity extends Activity implements OnSeekBarChangeListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
 SeekBar bar=(SeekBar)findViewById(R.id.seekBar1);
 bar.setOnSeekBarChangeListener(this);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
    // TODO Auto-generated method stub
    TextView tv=(TextView)findViewById(R.id.textView2);
    tv.setText(Integer.toString(progress)+"%");

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub

}
}
这是我的搜索栏xml代码-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 
android:background="#FFFFFF">

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Choose Your Progress"
    android:textColor="#000000"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_gravity="center"
    android:progressDrawable="@xml/progress"
    android:max="100"
    android:thumb="@xml/thumb"/>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:gravity="center"
    android:layout_gravity="center"
    android:paddingTop="10dp"
    android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

您不需要使用两个seekbar,但您只需使用一个seekbar并用两个拇指按住它,就可以实现最小和最大的相同功能 这是一个你可以使用的图书馆

您可以使用下面的代码

private final Thumb getClosestThumb(float touchX)

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

Android widget类库只有一个滑块控件,seekbar只有一个thumb控件。在网上做了一些研究,发现了这个很酷的定制小部件,range seek bar

你可以按照下面的任何一个


范围seekbar。还有其他提供大量定制的库。如果您想进行更多的交互式设计,请查找材质范围栏。

完全定制双向和单向搜索栏,您可以提供拇指颜色等

加上你的梯度

dependencies {
compile 'com.crystal:crystalrangeseekbar:1.0.0' 
}



setOnRangeBarChangeListener(新的rangebar.OnRangeBarChangeListener(){
@凌驾
public void onRangeChangeListener(RangeBar RangeBar,int leftPinIndex,
int rightPinIndex,
字符串leftPinValue、字符串rightPinValue){
}
});

我认为此链接也可能有帮助。 关于这一点,我们在网站上有一个解释


既然已正式添加到材质组件并支持所需的选项,我建议使用它而不是外部库

首先,应将视图添加到XML布局中:


然后将初始滑块值添加到数组中


20
70
之后,您可以访问代码中的RangeSlaider值:

binding.rangeSeekBar.addOnChangeListener { slider, value, fromUser ->
    Logger.d(slider.values)
}
其中,
values
是一个有两个成员的浮动列表

,您可以使用我的浮动列表。它有很多删节。它支持在两个方向上寻求进展


检查这个view@Andy谢谢,这是“如何将此代码添加到活动”的全部函数。如何使用此代码请帮助我!!他发布的库包含示例代码。“你应该读一读。”内森沃尔特谢谢我读了。。但如何将其整合到活动中。。如何使用这个??你能帮我说出来吗?你真的读过代码了吗?非常清楚。谢谢这是一个代码或一个库,我对它还不熟悉,你能详细帮助我吗…这是Seekbarth的库这个库很有用。但是你能告诉我如何设置初始值吗?我的意思是,最初两个点都应该到达某个点。这个库非常好,尽管圆的半径似乎不可配置,即使它们有一个参数(app:corner_radius)。因此,如果你不在乎圆圈是相当大的,是一个伟大的自定义范围寻找酒吧。
<com.crystal.crystalrangeseekbar.widgets.BubbleThumbRangeSeekbar
android:id="@+id/rangeSeekbar5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:corner_radius="10"
app:min_value="0"
app:max_value="100"
app:steps="5"
app:bar_color="#F7BB88"
app:bar_highlight_color="#E07416"
app:left_thumb_image="@drawable/thumb"
app:right_thumb_image="@drawable/thumb"
app:left_thumb_image_pressed="@drawable/thumb_pressed"
app:right_thumb_image_pressed="@drawable/thumb_pressed"
app:data_type="_integer"/>
        <com.appyvet.rangebar.RangeBar
            xmlns:custom="http://schemas.android.com/apk/res-auto"
            android:id="@+id/SearchrangeSeekbarAge"
            android:layout_width="match_parent"
            android:layout_height="72dp"
            custom:tickStart="18"
            custom:tickInterval="1"
            custom:tickEnd="70" />


        <com.appyvet.rangebar.RangeBar
            xmlns:custom="http://schemas.android.com/apk/res-auto"
            android:id="@+id/SearchrangeSeekbarHeight"
            android:layout_width="match_parent"
            android:layout_height="72dp"
            custom:tickStart="4.5"
            custom:tickInterval="0.10"
            custom:tickEnd="7.0" />


rangebar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
        @Override
        public void onRangeChangeListener(RangeBar rangeBar, int leftPinIndex,
                int rightPinIndex,
                String leftPinValue, String rightPinValue) {
        }
    });
    <org.florescu.android.rangeseekbar.RangeSeekBar
        android:id="@+id/rangebar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:thumbNormal="@drawable/ic_keyboard_arrow_down_black_24dp"
        app:thumbPressed="@drawable/ic_keyboard_arrow_down_black_24dp"/>
binding.rangeSeekBar.addOnChangeListener { slider, value, fromUser ->
    Logger.d(slider.values)
}