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 realize TextView Vertical Scroll in php LVB Source Code

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to implement vertical scrolling of TextView in php LVB source code? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Public class AutoScrollTextView extends TextSwitcher implements ViewSwitcher.ViewFactory {private static final int FLAG_START_AUTO_SCROLL = 1001; private static final int FLAG_STOP_AUTO_SCROLL = 1002; / * * rotation interval * / private int scrollDuration = 2000; / * * Animation time * / private int animDuration = 1000; / * * text size * / private float mTextSize = 14 / * text Padding * / private int mPadding = 20; / * * text color * / private int textColor = Color.BLACK; private OnItemClickListener itemClickListener; private Context mContext; / * currently displays ID * / private volatile int currentId =-1 of Item; private CopyOnWriteArrayList textList; private Handler handler; public AutoScrollTextView (Context context) {this (context, null) MContext = context;} public AutoScrollTextView (Context context, AttributeSet attrs) {super (context, attrs); mContext = context; init ();} @ SuppressLint ("HandlerLeak") private void init () {textList = new CopyOnWriteArrayList () Handler = new Handler () {@ Override public void handleMessage (Message msg) {switch (msg.what) {case FLAG_START_AUTO_SCROLL: if (textList.size () > 0) {currentId++ SetText (textList.get (currentId% textList.size ();} handler.sendEmptyMessageDelayed (FLAG_START_AUTO_SCROLL, scrollDuration); break; case FLAG_STOP_AUTO_SCROLL: handler.removeMessages (FLAG_START_AUTO_SCROLL) Break;}; setFactory (this); Animation in = new TranslateAnimation (0,0,300,0); in.setDuration (animDuration); in.setInterpolator (new AccelerateInterpolator ()); Animation out = new TranslateAnimation (0,0,0,300); out.setDuration (animDuration) Out.setInterpolator (new AccelerateInterpolator ()); setInAnimation (in); setOutAnimation (out);} / * set data source * * @ param titles * / public void setTextList (ArrayList titles) {textList.clear (); textList.addAll (titles); currentId =-1 } public void setText1 (String text) {if (TextUtils.isEmpty (text)) {return;} stopAutoScroll (); int width = getWidth ()-mPadding * 2; TextPaint paint = new TextPaint (); paint.setTextSize (TypedValue.applyDimension (TypedValue.COMPLEX_UNIT_SP, mTextSize, mContext.getResources (). GetDisplayMetrics ()); if (width)

< paint.measureText(" ")) { return; } List lineList = new ArrayList(); StringBuilder newLine = new StringBuilder(); for (int i = 0; i < text.length(); i++) { if ('\n' == text.charAt(i)) { lineList.add(newLine.toString()); newLine.setLength(0); } else { newLine.append(text.charAt(i)); if (paint.measureText(newLine.toString()) >

Width) {lineList.add (newLine.toString (). Substring (0, newLine.toString (). Length ()-1)); Imuri; newLine.setLength (0) } else {if (I = = text.length ()-1) {lineList.add (newLine.toString ()); newLine.setLength (0); break } textList.clear (); textList.addAll (lineList); currentId =-1;} / * * start carousel * / public void startAutoScroll () {if (textList.isEmpty ()) {return } if (textList.size () = = 1) {setText (textList.get (0)); return;} handler.removeCallbacksAndMessages (null); handler.sendEmptyMessage (FLAG_START_AUTO_SCROLL);} / * stop carousel * / public void stopAutoScroll () {handler.sendEmptyMessage (FLAG_STOP_AUTO_SCROLL) } @ Override public View makeView () {TextView t = new TextView (mContext); t.setGravity (Gravity.CENTER_VERTICAL | Gravity.LEFT); t.setMaxLines (1); t.setPadding (mPadding, mPadding); t.setTextColor (textColor); t.setTextSize (mTextSize); t.setClickable (true) T.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {if (itemClickListener! = null & & textList.size () > 0 & & currentId! =-1) {itemClickListener.onItemClick (currentId% textList.size ()); return t } / * set click event listening * / public void setOnItemClickListener (OnItemClickListener itemClickListener) {this.itemClickListener = itemClickListener } / * text click listener * / public interface OnItemClickListener {/ * Click callback * * @ param position currently click ID * / public void onItemClick (int position) }} this is the answer to the question about how the php LVB source code implements the vertical scrolling of TextView. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more relevant knowledge.

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