First of all, let me declare that this is a tripartite control. I just want to introduce its usage here. Of course, you might say it's not a rotation chart. It's also necessary to use a third party. It's really a vegetable bee. Yes, I am a vegetable bee. But why do we have to make wheels by ourselves? There are many unavoidable problems in writing by ourselves.
Convenient Banner: A general-purpose advertisement board control, which makes it easy for you to achieve the advertisement header effect. Supporting infinite loops, you can set up automatic page turning and time (and very intelligent, finger touch will pause page turning, leaving the automatic start page turning. You can also set up the interface onPause without automatically turning pages, onResume then continue to automatically turn pages, and provide a variety of page turning effects. Compared with other advertisement bar controls, most of them need to change the source code to load network pictures, or help you integrate the image cache library that is not what you need. And this library can make you happy with code cleanliness. Without modifying the source code of the library, you can use any network picture library you like to cooperate with.
If you like to study source code, if you want to learn more, please refer to the original project address.
Convenient Banner original project address
I'm just going to give you a brief introduction.
I developed Android Studio (hereinafter referred to as AS)
1 If you develop with AS, it's easy to add compile'com.bigkoo:convenientbanner:2.0.5'to your build.gradle file.
Of course, if you are still using eclipse, then go to the above project address to download the demo copy rack package, say a piece of crap, or early transfer to AS bar is more convenient than eclipse intelligence.
2 Use in Layout File
<com.bigkoo.convenientbanner.ConvenientBanner
android:id="@+id/id_cb"
android:layout_width="match_parent"
android:layout_height="100dp"
app:canLoop="true" //Control cycle or not
/>
- 1
- 2
- 3
- 4
- 5
- 6
Use in 3 code
(1) Customize your holder, a very simple way to implement the Holder interface without implementing it
public class ImageViewHolder implements Holder<Integer>{
private ImageView imageView;
@Override
public View createView(Context context) {
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
return imageView;
}
@Override
public void UpdateUI(Context context, int position, Integer data) {
imageView.setImageResource(data);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
(2) Set Pages for Convenient Banner
mCb.setPages(new CBViewHolderCreator<ImageViewHolder>() {
@Override
public ImageViewHolder createHolder() {
return new ImageViewHolder();
}
},mImageList)
.setPageIndicator(new int[] {R.drawable.ponit_normal,R.drawable.point_select}) //Set two points as indicators
.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL); //Set the direction of the indicator to be centered horizontally
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
(3) Remember to set mCb.startTurning(2000) to open the rotation chart cycle page turning, so that a rotation map framework is built. (4) The event of clicking on the entries of the rotation chart. In the project, clicking on the rotation chart entries usually has the jump page operation. We can handle the jump page operation in this method.
mCb.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position) {
Toast.makeText(MainActivity.this,"Click on the entry"+position,Toast.LENGTH_LONG).show();
}
});
- 1
- 2
- 3
- 4
- 5
- 6
(5) If you load a network picture, remember to add network privileges to the list file
4. Introduction of Common Methods
mCb.setPageIndicator(int[]) This is the way to set the indicator.
mCb.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign) Setting Indicator Direction
mCb.startTurning(2000); //Setting Start Rotary and Rotary Timing Suggestions in onResume Method
mCb.stopTurning(); //Stop the rotation recommendation in the onPause method
mCb.setManualPageable(false);//Settings cannot be manually affected. By default, finger-touched rotation maps cannot be turned over.
mCb.setCanLoop(boolean); //Default true, set whether the rotation map is rotated
- 1
- 2
- 3
- 4
- 5
- 6
5 Source code download
6 Effect Picture