English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Recently used a carousel figure with infinite scrolling and automatic playback, and there are various problems on the Internet, so I wrote a universal control CarouselFigureView myself.
Features:
1.The view that can be scrolled can be defined by yourself, and it does not necessarily have to be an ImageView2.The indicator is displayed by default, but it can be hidden3.You can set the color, spacing, and size of the indicator 4.If you have a basic understanding, you can modify the code to change the position of the indicator, which should not be difficult5.You can enable and disable automatic scrolling, and when you enable scrolling, you can set the interval of the scroll time, the default3000 milliseconds
Let's take a look at the effect first:
Then let's take a look at the code
xml code
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="com.winston.base.myviewpager.MainActivity"> <com.winston.base.myviewpager.carousefigure.CarouselFigureView android:id="@"+id/carouselFigureView" android:layout_width="match_parent" android:layout_height="match_parent"/> </FrameLayout>
activity code
<pre name="code" class="html">package com.winston.base.myviewpager; import android.os.Bundle; import android.support.v;7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; import com.nostra;13.universalimageloader.core.ImageLoader; import com.nostra;13.universalimageloader.core.ImageLoaderConfiguration; import com.winston.base.myviewpager.carousefigure.CarouseFigureBaseAdapter; import com.winston.base.myviewpager.carousefigure.CarouselFigureView; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private List<String> urls = new ArrayList<>(); private CarouselFigureView carouselFigureView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this)); urls.add("http://h.hiphotos.baidu.com/image/h%3D300/sign=c9dd5806ab6eddc439e7b2fb09dab6a2/377adab44aed2e734cfdf0cf8101a18b87d6fa39.jpg"); urls.add("http://e.hiphotos.baidu.com/image/h%3D300/sign=7aac96eab0003af352bada60052bc619/b58f8c5494eef01f76566e26e6fe9925bd317d96.jpg"); urls.add("http://b.hiphotos.baidu.com/image/h%3D300/sign=c5d06d0ea5cc7cd9e52d32d909002104/32fa828ba61ea8d3946002e7910a304e241f5896.jpg"); urls.add("http://f.hiphotos.baidu.com/image/h%3D360/sign=76a2918f0bb30f242a9aea05f894d192/a8014c086e061d9507500dd67ff40ad163d9cacd.jpg"); setContentView(R.layout.activity_main); carouselFigureView = (CarouselFigureView)findViewById(R.id.carouselFigureView); carouselFigureView.setAdapter(new CarouselFigureBaseAdapter(){ <pre name="code" class="html"><span style="white-space:pre"> </span>//Return the number of views to be displayed in the carousel <span style="white-space:pre"> </span> @Override public int getSize() { return urls.size(); {} <span style="white-space:pre"> </span>//This is the key, return the corresponding view (i.e., the corresponding carousel image) based on position @Override public View getView(int position) { ImageView view = new ImageView(MainActivity.this); ImageLoader.getInstance().displayImage(urls.get(position), view); return view; {} ); //Set the size of the indicator point, default8 unit dp carouselFigureView.setPointSize(16); //Set the color of the indicator points, default selected red, others gray // carouselFigureView.setPointColor(Color.BLUE,Color.BLACK); //Set the distance from the indicator point to the bottom, default40 Unit dp // carouselFigureView.setIndicatorMarginBottom(260); //Set the spacing of the indicator points, default20 Unit dp carouselFigureView.setPointSpacing(40); //Set whether to display the indicator, default display // carouselFigureView.isShowIndicator(false); {} @Override protected void onResume() { super.onResume(); //Start Carousel carouselFigureView.start(); {} @Override protected void onPause() { super.onPause(); //Stop Carousel carouselFigureView.stop(); {} {}
The above-mentioned is the Android implementation of the CarouselFigureView control that realizes infinite loop automatic playback with indicators based on ViewPager introduced by the editor to everyone. Hope it will be helpful to everyone. If you have any questions, please leave a message. The editor will reply to everyone in time. Here, we also thank everyone for their support of the Yelling Tutorial website!
Statement: The content of this article is from the network, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not edit the content manually, and does not bear the relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (when sending an email, please replace # with @ for reporting, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)