CarouselPicker

CarouselPicker

项目地址:GoodieBag/CarouselPicker 

简介:A Carousel picker library for android which supports both text and icons . :sparkles:

A Carousel picker library for android which supports both text and icons . :pouting_cat:

  

Gradle Dependency

Add this in your root build.gradle file at the end of repositories:

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

Add the dependency :

dependencies {
            implementation 'com.github.GoodieBag:CarouselPicker:v1.1'
    }

Sync the gradle and that's it! :+1:

Features :

  • Supports icons and text or a mixture of both as items of the picker.
  • Gives a nice carousel view of the items.
  • Page change listener exists to monitor the current selected item.

Usage

XML :

<in.goodiebag.carouselpicker.CarouselPicker
        android:id="@+id/carousel"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#CCC"
        app:items_visible="three" />

items_visible represents the number of pages visible on the screen. Three, five and seven are the available options.

Java :

Carousel picker supports both images and text or a mixture of both !

CarouselPicker carouselPicker = (CarouselPicker) findViewById(R.id.carousel);

// Case 1 : To populate the picker with images
List<CarouselPicker.PickerItem> imageItems = new ArrayList<>();
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i1));
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i2));
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i3));
//Create an adapter
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this, imageItems, 0);
//Set the adapter
carouselPicker.setAdapter(imageAdapter);

//Case 2 : To populate the picker with text
List<CarouselPicker.PickerItem> textItems = new ArrayList<>();
//20 here represents the textSize in dp, change it to the value you want.
textItems.add(new CarouselPicker.TextItem("hi", 20));
textItems.add(new CarouselPicker.TextItem("hi", 20));
textItems.add(new CarouselPicker.TextItem("hi", 20));
CarouselPicker.CarouselViewAdapter textAdapter = new CarouselPicker.CarouselViewAdapter(this, textItems, 0);
carouselPicker.setAdapter(textAdapter);

//Case 3 : To populate the picker with both images and text
List<CarouselPicker.PickerItem> mixItems = new ArrayList<>();
mixItems.add(new CarouselPicker.DrawableItem(R.drawable.i1));
mixItems.add(new CarouselPicker.TextItem("hi", 20));
mixItems.add(new CarouselPicker.DrawableItem(R.drawable.i2));
mixItems.add(new CarouselPicker.TextItem("hi", 20));
CarouselPicker.CarouselViewAdapter mixAdapter = new CarouselPicker.CarouselViewAdapter(this, mixItems, 0);
carouselPicker.setAdapter(mixAdapter);

Decorations :

  • Text color for text items can be set using adapter.setTextColor(colorInt)

Listeners :

carouselPicker.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                //position of the selected item
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值