Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ImageSlider to realize the effect of a cool roving advertisement in Android

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use ImageSlider in Android to achieve a cool round-robin advertising effect". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use ImageSlider to achieve a cool rotation advertising effect in Android".

1. Gradle dependency configuration

We are using the android Studio 2.2.3 development tool here. For more information on how to reference a third-party library in Eclipse, please refer to the AndroidImageSlider source code description. Integrate the dependencies of third-party libraries in the build.gradle file.

Xmldependencies {compile 'com.daimajia.slider:library:1.1.5@aar' compile' com.squareup.picasso:picasso:2.5.2' compile 'com.nineoldandroids:library:2.4.0' compile' com.android.support:support-v4:25.2.0'}

two。 Add permission

To use this framework, you also need to add corresponding permissions, namely, network permissions and read file permissions.

Xml

3. Add to layout Layout

Add SliderLayout to the appropriate layout file Layout.

Xml

If you need a custom PagerIndicator, you can customize it, or you can use the one that comes with the framework. Here is the source code of the custom PagerIndicator.

Xml

4. Define and configure SliderLayout in Activity/Fragment

The first thing to do is to get the SliderLayout control and the custom Indicator.

XmlmSlider = (SliderLayout) view.findViewById (R.id.home_slider_ad); indicator = (PagerIndicator) view.findViewById (R.id.home_indicator_ad)

Then there is the data ready for the test. Here I define an entity class BannerInfo, which includes the picture imgUrl and the description content name. Once the entity class is defined, the corresponding test data is set up and added to the scrolling picture list listBanner.

Xmlprivate void getBannerData () {BannerInfo bannerInfo_01 = new BannerInfo (); bannerInfo_01.setName ("Speaker Carnival"); bannerInfo_01.setImgUrl ("http://7mno4h.com2.z0.glb.qiniucdn.com/5608f3b5Nc8d90151.jpg"); BannerInfo bannerInfo_02 = new BannerInfo (); bannerInfo_02.setName (" National Day ceremony on Mobile phone "); bannerInfo_02.setImgUrl (" http://7mno4h.com2.z0.glb.qiniucdn.com/5608eb8cN9b9a0a39.jpg"); BannerInfo bannerInfo_03 = new BannerInfo ()) " BannerInfo_03.setName ("IT Life"); bannerInfo_03.setImgUrl ("http://7mno4h.com2.z0.glb.qiniucdn.com/5608cae6Nbb1a39f9.jpg"); listBanner.add (bannerInfo_01); listBanner.add (bannerInfo_02); listBanner.add (bannerInfo_03);}

The next step is to configure the relevant properties of SliderLayout, add custom Indicator, animate effects, add picture list data, and set listening events

Xmlprivate void initSlider () {if (listBanner! = null) {for (BannerInfo bannerInfo: listBanner) {TextSliderView textSliderView = new TextSliderView (this.getActivity ()); textSliderView.image (bannerInfo.getImgUrl ()) .description (bannerInfo.getName ()) .setScaleType (BaseSliderView.ScaleType.CenterCrop) .setOnSliderClickListener (this); mSlider.addSlider (textSliderView);}} mSlider.setCustomIndicator (indicator); mSlider.setCustomAnimation (new DescriptionAnimation ()); mSlider.setPresetTransformer (SliderLayout.Transformer.RotateUp); mSlider.setDuration (3000) MSlider.addOnPageChangeListener (this);}

5. Stop SliderLayout scrolling in onStop ()

Before the end of the Activity/Fragment life cycle, you need to stop scrolling the picture to prevent memory overflow and other problems.

Xml@Override public void onStop () {/ / To prevent a memory leak on rotation, make sure to call stopAutoCycle () on the slider before activity or fragment is destroyed mSlider.stopAutoCycle (); super.onStop () } Thank you for your reading. The above is the content of "how to use ImageSlider in Android to achieve a cool round-show advertising effect". After the study of this article, I believe you have a deeper understanding of how to use ImageSlider to achieve a cool round-show advertising effect in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report