Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sayyam/carouselview
A simple library to add carousel view in android app.
https://github.com/sayyam/carouselview
Last synced: 3 months ago
JSON representation
A simple library to add carousel view in android app.
- Host: GitHub
- URL: https://github.com/sayyam/carouselview
- Owner: sayyam
- License: apache-2.0
- Created: 2016-03-15T11:22:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-18T12:24:46.000Z (over 4 years ago)
- Last Synced: 2024-07-01T04:47:53.849Z (4 months ago)
- Language: Java
- Homepage:
- Size: 9.07 MB
- Stars: 1,149
- Watchers: 34
- Forks: 258
- Open Issues: 75
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-android-ui - carouselview - Android轮播框库 (轮播图)
README
CarouselView
=======
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-CarouselView-green.svg?style=true)](https://android-arsenal.com/details/1/3289)A simple yet flexible library to add carousel view in your android application.
Download
--------
### Gradle:
```groovy
compile 'com.synnapps:carouselview:0.1.5'
```
### Maven:
```xmlcom.synnapps
carouselview
0.1.5
pom```
Usage
--------### Include following code in your layout:
```xml
```
### Include following code in your activity:
```java
public class SampleCarouselViewActivity extends AppCompatActivity {CarouselView carouselView;
int[] sampleImages = {R.drawable.image_1, R.drawable.image_2, R.drawable.image_3, R.drawable.image_4, R.drawable.image_5};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_carousel_view);carouselView = (CarouselView) findViewById(R.id.carouselView);
carouselView.setPageCount(sampleImages.length);carouselView.setImageListener(imageListener);
}ImageListener imageListener = new ImageListener() {
@Override
public void setImageForPosition(int position, ImageView imageView) {
imageView.setImageResource(sampleImages[position]);
}
};}
```### If you want to add custom view, implement ```ViewListener```.
```javapublic class SampleCarouselViewActivity extends AppCompatActivity {
CarouselView customCarouselView;
int NUMBER_OF_PAGES = 5;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_carousel_view);customCarouselView = (CarouselView) findViewById(R.id.customCarouselView);
customCarouselView.setPageCount(NUMBER_OF_PAGES);
// set ViewListener for custom view
customCarouselView.setViewListener(viewListener);
}ViewListener viewListener = new ViewListener() {
@Override
public View setViewForPosition(int position) {
View customView = getLayoutInflater().inflate(R.layout.view_custom, null);
//set view attributes here
return customView;
}
};```
### If you'd like to receive touch events for each image
```java
customCarouselView.setImageClickListener(new ImageClickListener() {
@Override
public void onClick(int position) {
Toast.makeText(SampleCarouselViewActivity.this, "Clicked item: "+ position, Toast.LENGTH_SHORT).show();
}
});
```### If using ProGuard add this line to your proguard-rules.pro:
```
-keep class com.synnapps.carouselview.** { *; }
```### Supported xml Attributes
| Attribute | Description | Values |
| ------------------------------------------|--------------------------------------------------------------------|------------------------------|
| app:slideInterval | Interval per page in ms. | integer |
| app:indicatorGravity | Gravity of the indicator. (Just like layout_gravity) | gravity |
| app:indicatorOrientation | Orientation of the indicator. | [horizontal, vertical] |
| app:indicatorVisibility | Set visibility of indicator. | [visible,invisible,gone] |
| app:fillColor | Color of the filled circle that represents the current page. | color |
| app:pageColor | Color of the filled circles that represents pages. | color |
| app:radius | Radius of the circles. This is also the spacing between circles. | dimension |
| app:snap | Whether or not the selected indicator snaps to the circles. | boolean |
| app:strokeColor | Width of the stroke used to draw the circles. | color |
| app:autoPlay | Whether or not to auto play. Default: true | boolean |
| app:disableAutoPlayOnUserInteraction | Disables autoPlay when user interacts. Default: false | boolean |
| app:indicatorMarginHorizontal | Sets horizontal margin for Indicator in Carousel View | dimension |
| app:indicatorMarginVertical | Sets vertical margin for Indicator in Carousel View | dimension |
| app:pageTransformInterval | Sets speed at which page will slide from one to another in ms. | integer |
| app:pageTransformer | Sets page transition animation. | [zoom,flow,depth,slide_over] |
| app:animateOnBoundary | Sets whether to animate from last page. Default: true | boolean |_Note:_ Add ```xmlns:app="http://schemas.android.com/apk/res-auto"``` in your layout's root view.
Developed By
--------
- Sayyam Mehmood
- Muhammad RehanSpecial Thanks
--------This library uses code snippet from Jake Wharton's [ViewPagerIndicator](https://github.com/JakeWharton/ViewPagerIndicator) to display page indicator.
License
--------Copyright 2016 Sayyam.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.