Bubble-Picker

介绍:

一个类似apple-music的气泡选择效果。

运行效果:

使用说明:

在root build.gradle中添加:

allprojects {
    repositories {
    ...
    maven { url "https://jitpack.io" }
    }
}

添加依赖:

dependencies {
    compile 'com.github.igalata:Bubble-Picker:v0.1.2'
}

把 BubblePicker添加到你的 xml 布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.igalata.bubblepicker.rendering.BubblePicker
        android:id="@+id/picker"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:backgroundColor="@android:color/white" />
</FrameLayout>

重写 onResume() 和 onPause()方法以调用BubblePicker的同名方法

Kotlin

override fun onResume() {
      super.onResume()
      picker.onResume()
}
override fun onPause() {
      super.onPause()
      picker.onPause()
}

Java

@Override
protected void onResume() {
      super.onResume();
      picker.onResume();
}
@Override
protected void onPause() {
      super.onPause();
      picker.onPause();
}

把PickerItem列表传递给BubblePicker

Kotlin

val titles = resources.getStringArray(R.array.countries)
val colors = resources.obtainTypedArray(R.array.colors)
val images = resources.obtainTypedArray(R.array.images)
picker.items = ArrayList()
titles.forEachIndexed { i, country ->
            picker.items?.add(PickerItem(country,
                    gradient = BubbleGradient(colors.getColor((i * 2) % 8, 0), colors.getColor((i * 2) % 8 + 1, 0),
                            BubbleGradient.VERTICAL),
                    typeface = mediumTypeface,
                    textColor = ContextCompat.getColor(this, android.R.color.white),
                    image = ContextCompat.getDrawable(this, images.getResourceId(i, 0))))
}

Java

final String\[\] titles = getResources().getStringArray(R.array.countries);
final TypedArray colors = getResources().obtainTypedArray(R.array.colors);
final TypedArray images = getResources().obtainTypedArray(R.array.images);
picker.setItems(new ArrayList<PickerItem>() {{
      for (int i = 0; i < titles.length; ++i) {
                add(new PickerItem(titles\[i\], colors.getColor((i * 2) % 8, 0),
                        ContextCompat.getColor(TestActivity.this, android.R.color.white),
                        ContextCompat.getDrawable(TestActivity.this, images.getResourceId(i, 0))));
      }
}});

Specify the BubblePickerListener to get notified about events

Kotlin

picker.listener = object : BubblePickerListener {
            override fun onBubbleSelected(item: PickerItem) {
            }
            override fun onBubbleDeselected(item: PickerItem) {
            }
}

Java

picker.setListener(new BubblePickerListener() {
            @Override
            public void onBubbleSelected(@NotNull PickerItem item) {
                
            }
            @Override
            public void onBubbleDeselected(@NotNull PickerItem item) {
            }
});

要得到所有的selected item使用picker.selectedItems变量(Kotlin)或者picker.getSelectedItems() 方法(Java)。

已下载
0