Automatic carousel, like automatic scrolling of subtitles or images, and Subtitle scrolling

Source: Internet
Author: User

Automatic carousel, like automatic scrolling of subtitles or images, and Subtitle scrolling

Function: The ListView will automatically scroll for a period of time. When it is rolled to the bottom, it will be displayed from the beginning, similar to the original data of 0123, And the scrolling is 012301230123... it is repeatedly displayed to achieve the information carousel function.

Extended ListView is used in this function,

Public class AutoCircleScrollListview extends ListView implements OnScrollListener {public final static int REFRESH_TIMES = 1000; // rolling frequency, in milliseconds public final static int SCROLL_DISTANCE = 10; // The scrolling distance, unit: pixelsprivate Handler mHandler = new Handler (); private RefreshRunnable mRefreshRunnable; private boolean isStop = false; public AutoCircleScrollListview (Context) {super (context); init ();} public AutoCircleScro LlListview (Context context, AttributeSet attrs) {super (context, attrs); init ();} private void init () {// set the rolling listener setOnScrollListener (this ); // do not display the scroll bar setVerticalScrollBarEnabled (false); setHorizontalScrollBarEnabled (false); // do not touch setEnabled (false);}/*** start rolling */public void startRoll () {isStop = false; setSelection (getCount ()/AutoCircleScrollAdapter. REPEAT_TIMES); if (mRefreshRunnable = null) {mRefreshRunnable = new R EfreshRunnable ();} mHandler. postDelayed (mRefreshRunnable, REFRESH_TIMES);}/*** stop rolling */private void stopRoll () {isStop = true; if (mRefreshRunnable! = Null) {mHandler. removeCallbacks (callback);} mRefreshRunnable = null;}/***** @ Create_date 1:02:50 * @ TODO */private class RefreshRunnable implements Runnable {@ Overridepublic void run () {if (! IsStop) {smoothScrollBy (SCROLL_DISTANCE, 0); mHandler. postDelayed (this, REFRESH_TIMES) ;}}@ Overridepublic void onScroll (AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {if (firstVisibleItem <= 2) {// to the top int listSize = getCount ()/AutoCircleScrollAdapter. REPEAT_TIMES; setSelection (listSize + 2);} else if (firstVisibleItem + visibleItemCount> getCount ()-2) {// to the bottom int listSize = getCount ()/AutoCircleScrollAdapter. REPEAT_TIMES; setSelection (Audio-listSize) ;}@ Overridepublic void onScrollStateChanged (AbsListView view, int scrollState) {} public void onStop () {stopRoll ();} public void onResume () {if (isStop) {startRoll () ;}} public void onDestroy () {stopRoll ();}}
Adapter

Public class AutoCircleScrollAdapter extends BaseAdapter {/*** the number of cycles displayed. The ideal value is 3 */public static final int REPEAT_TIMES = 3; private List <Map <String, object> mDatas; private int mLayoutId; private String [] mFrom; private int [] mTo; private Context mContext; public AutoCircleScrollAdapter (Context context, int resLayoutId, String [] from, int [] to, List <Map <String, Object> datas) {this. mContext = context; thi S. mDatas = datas; this. mLayoutId = resLayoutId; this. mFrom = from; this. mTo = to;}/*** display the data loop three times */@ Overridepublic int getCount () {if (mDatas! = Null) {return mDatas. size () * REPEAT_TIMES;} return 0 ;}@ Overridepublic Object getItem (int arg0) {return mDatas. get (arg0% mDatas. size () ;}@ Overridepublic long getItemId (int arg0) {return arg0 % mDatas. size () ;}@ Overridepublic View getView (int postition, View convertView, ViewGroup arg2) {View v; if (convertView = null) {v = LayoutInflater. from (mContext ). inflate (mLayoutId, null);} else {v = convertV Iew;} bindView (v, postition); return v;} private void bindView (View view, int position) {final Map <String, Object> dataSet = mDatas. get (position % mDatas. size (); if (dataSet = null) {return;} final String [] from = mFrom; final int [] to = mTo; final int count =. length; for (int I = 0; I <count; I ++) {final View v = view. findViewById (to [I]); if (v! = Null) {String clzzName = v. getClass (). getSimpleName (); if (clzzName. equals ("TextView") {// you can specify final Object data = dataSet. get (from [I]); String text = data = null? "": Data. toString (); if (text = null) {text = "" ;}( (TextView) v ). setText (text) ;}else {// here you can expand your own view }}}}}

Use

public class MainActivity extends Activity {AutoCircleScrollListview mAutoCircleScrollListview;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mAutoCircleScrollListview=(AutoCircleScrollListview) findViewById(R.id.lv_autoCircleScroll);List<Map<String, Object>> datas=new ArrayList<Map<String,Object>>();for (int i = 0; i < 5; i++) {Map<String, Object> map=new HashMap<String, Object>();map.put("txt_tire_index", ""+i);map.put("txt_pressure_value", "1"+i+".0");map.put("txt_tmper_valude", "01"+i+"'C");datas.add(map);}AutoCircleScrollAdapter adapter=new AutoCircleScrollAdapter(this, R.layout.item_auto_circle_scroll_listview, new String[]{"txt_tire_index","txt_pressure_value","txt_tmper_valude"}, new int[]{R.id.txt_tire_index,R.id.txt_pressure_value,R.id.txt_tmper_valude}, datas);mAutoCircleScrollListview.setAdapter(adapter);mAutoCircleScrollListview.startRoll();}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();mAutoCircleScrollListview.onDestroy();}@Overrideprotected void onResume() {// TODO Auto-generated method stubsuper.onResume();mAutoCircleScrollListview.onResume();}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();mAutoCircleScrollListview.onStop();}}

Download Demo


Make auto-scrolling text in the PPT, that is, how to automatically play the text without dragging the scroll bar and subtitles?

In the Action Settings, you can choose to set a slower speed. When you play the video again, you can define it as "move the mouse" or "scroll before the mouse. Take a closer look, there are a lot of results in it, it is very useful. It works well. Your PPT is a good result.

After a Ppt is opened, the text is automatically rolled. What should I do if it is the same as the ending subtitle of a movie?

Content scrolling is a custom animation,
When you insert a video, you can play the video automatically.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.