DiscreteSeekbar在github上的项目主页是:https://github.com/AnderWeb/discreteSeekBar
DiscreteSeekbar可以自定制的属性很多,可以在其github的项目主页上查看。DiscreteSeekbar可以像Android 原生的Seekbar一样使用。
使用方法:
写布局activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.zzw.testdiscreteseekbar.MainActivity" > <!-- app:dsb_max 最大值 -->
<!-- app:dsb_min 最小值 -->
<!-- app:dsb_value 当前值 --> <org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
android:id="@+id/discreteSeekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
app:dsb_max="10"
app:dsb_min="-10"
app:dsb_value="0" /> <!-- app:dsb_indicatorFormatter="值 %d"表示显示出来的值形如:值 37 -->
<!-- app:dsb_indicatorColor="@android:color/holo_red_light" 气泡显示的颜色 -->
<!-- app:dsb_rippleColor="@android:color/holo_red_light" 手指拉动时候手指位置的颜色 --> <org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
android:id="@+id/discreteSeekBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
app:dsb_allowTrackClickToDrag="false"
app:dsb_indicatorColor="@android:color/holo_red_light"
app:dsb_indicatorFormatter="值 %d"
app:dsb_rippleColor="@android:color/holo_red_light" /> <!-- app:dsb_indicatorFormatter="%04d"代表有几位数 ,0后面是几就是几位数 如:0013,0135,1000 --> <org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
android:id="@+id/discreteSeekBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
app:dsb_indicatorColor="@android:color/holo_green_light"
app:dsb_indicatorFormatter="%04d"
app:dsb_max="1000"
app:dsb_min="1"
app:dsb_rippleColor="@android:color/holo_blue_light" /> </LinearLayout>
MainActivity.java可以设置参数:
package com.zzw.testdiscreteseekbar; import org.adw.library.widgets.discreteseekbar.DiscreteSeekBar;
import org.adw.library.widgets.discreteseekbar.DiscreteSeekBar.NumericTransformer;
import org.adw.library.widgets.discreteseekbar.DiscreteSeekBar.OnProgressChangeListener; import android.app.Activity;
import android.os.Bundle;
import android.util.Log; public class MainActivity extends Activity { protected static final String TAG = "MainActivity"; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); DiscreteSeekBar discreteSeekBar1 = (DiscreteSeekBar) findViewById(R.id.discreteSeekBar1);
discreteSeekBar1.setNumericTransformer(new NumericTransformer() { @Override
public int transform(int value) { return value * 100;
}
}); DiscreteSeekBar discreteSeekBar2 = (DiscreteSeekBar) findViewById(R.id.discreteSeekBar2);
discreteSeekBar2.setOnProgressChangeListener(new OnProgressChangeListener() { @Override
public void onStopTrackingTouch(DiscreteSeekBar seekBar) { } @Override
public void onStartTrackingTouch(DiscreteSeekBar seekBar) { } @Override
public void onProgressChanged(DiscreteSeekBar seekBar, int value,
boolean fromUser) {
Log.d(TAG, value+"");
}
});
} }