他自己寫的 seekbar widget.
project 包含 widget library 和 demo project
使用時只要library project 就可以。
Android Studio 的 project 中,使用這個 library 的方法:
- File -- New -- Module , 出現新 Dialog
- Dialog 中出現很多 item, 選 'Import Gradle Project',然後 Next
- Source Directory 選到 StartPointSeekBar/Library
- 要給名稱,.,就沿用 library 好了
使用:
在 layout xml 中首先要加入:
xmlns:custom="http://schemas.android.com/apk/res-auto"
例如..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
然後就可以在 xml 中加入 這個 seekbar 了..
<com.vashisthg.startpointseekbar.StartPointSeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
custom:minValue="-40.0"
custom:maxValue="+40.0"
/>
使用的 app build.gradle 的 dependency 要加上:
compile project(':library')
要是在 gradle-experimental 的話,要大幅度修改:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.3"
defaultConfig.with {
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 23
versionCode = 2
versionName = "1.2"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-android.txt'))
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Progress Change Handler 跟一般 Seekbar 一樣..
StartPointSeekBar seekBar = (StartPointSeekBar) findViewById(R.id.seek_bar);
seekBar.setOnSeekBarChangeListener(new StartPointSeekBar.OnSeekBarChangeListener() {
@Override
public void onOnSeekBarValueChange(StartPointSeekBar bar, double value) {
Log.d(LOGTAG, "seekbar value:" + value);
}
});
// setting progress on your own
seekBar.setProgress(+20);
}