# Banner-Slider **Repository Path**: baijuncheng-open-source/banner-slider ## Basic Information - **Project Name**: Banner-Slider - **Description**: 一个简易的图片滑动的库 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-05-31 - **Last Updated**: 2024-11-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Banner-Slider Banner slider is an easy to use library for making beautiful sliders in your ohos hap. ### Preview ![](img/bannerslider.gif) ### How to use **Gradle** add this line to your module build.gradle dependecies block: ``` dependencies { implementation ‘com.gitee.baijuncheng-open-source:Banner-Slider:1.0.0’ } ``` ### How use this library **XML** ``` ``` **Java** **Step 1** : extend SliderAdapter in first step you must create an adapter to adapt your data model with slides. example implemented adapter with 3 slides: ``` public class MainSliderAdapter extends SliderAdapter { @Override public int getItemCount() { return 3; } @Override public void onBindImageSlide(Context context, int position, ImageSlideViewHolder viewHolder) { int resId = 0; switch (position) { case 1: resId = ResourceTable.Media_preview2; break; case 2: resId = ResourceTable.Media_preview3; break; default: resId = ResourceTable.Media_preview1; break; } PixelMap pixelMap = Utils.getPixelMapFromResource(context,resId); viewHolder.bindImageSlide(pixelMap,position); } } ``` **Step 2** : set your adapter on slider ``` slider = (Slider) findComponentById(ResourceTable.Id_banner_slider1); ... //delay for testing empty view functionality handler.postTask(new Runnable() { @Override public void run() { slider.setAdapter(new MainSliderAdapter()); } }, 1500); ``` ### You want more customization? Changing slides automatically in specifed periods interval attribute get miliseconds. ``` app:slider_animateIndicators="true" app:slider_emptyView="$layout:layout_empty_view" app:slider_indicatorSize="10vp" app:slider_interval="0" app:slider_loopSlides="true" app:slider_selectedSlideIndicator="$grahpic/indicator_circle_selected" app:slider_unselectedSlideIndicator="$grahpic/indicator_circle_unselected" ``` How set empty view, when banners not received from server yet? `app:slider_emptyView="$layout:layout_empty_view"` Change indicator sizes `app:slider_indicatorSize="10vp"` Set OnBannerClickListener ``` slider.setOnSlideClickListener(new OnSlideClickListener() { @Override public void onSlideClick(int position) { //Do what you want } }); }); ``` ### Change Log #### [1.0.0] - May , 2021 - 静态扫描,findbugs处理; ### Licence ``` Copyright 2016 Saeed Shahini 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 at http://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. ```