一个适用于 Android 的 HorizontalPicker 视图,支持文本和图标。 :sparkles:
A Horizontal picker library for android which supports both text and icons . :pouting_cat:
Add this in your root build.gradle file at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}Add the dependency :
dependencies {
compile 'com.github.GoodieBag:HorizontalPicker:v1.0'
}Sync the gradle and that's it! :+1:
P.S : itemWidth and itemHeight are not mandatory. If ignored, it is WRAP_CONTENT by default.
textColorSelector is only applicable when the items are textItems.
//If your picker needs to have text as items :
HorizontalPicker hpText = (HorizontalPicker) findViewById(R.id.picker);
List textItems = new ArrayList<>();
for(int i=1;i imageItems = new ArrayList<>();
imageItems.add(new HorizontalPicker.DrawableItem(R.drawable.example));
imageItems.add(new HorizontalPicker.DrawableItem(R.drawable.example2));
hpImage.setItems(imageItems);hpText.setSelectedIndex(index) to select an item programmatically.A listener exists to monitor the item selection change on slide or on tap.
HorizontalPicker.OnSelectionChangeListener listener = new HorizontalPicker.OnSelectionChangeListener() {
@Override
public void onItemSelect(HorizontalPicker picker, int index) {
HorizontalPicker.PickerItem selected = picker.getSelectedItem();
Toast.makeText(MainActivity.this, selected.hasDrawable() ? "Item at " + (picker.getSelectedIndex() + 1) + " is selected" : selected.getText() + " is selected", Toast.LENGTH_SHORT).show();
}
hpText.setChangeListener(listener);
When the HorizontalPicker is wrapped in an HorizontalScrollView the scroll to select feature of the picker does not work as expected. This will be fixed soon.
…暂无开放 Issues,或尚未同步最近议题。