php直播源碼如何實現(xiàn)TextView豎直滾動,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
公司主營業(yè)務:網(wǎng)站設計制作、網(wǎng)站設計、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出郊區(qū)免費做網(wǎng)站回饋大家。
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; /** * 輪播時間間隔 */ private int scrollDuration = 2000; /** * 動畫時間 */ private int animDuration = 1000; /** * 文字大小 */ private float mTextSize = 14; /** * 文字Padding */ private int mPadding = 20; /** * 文字顏色 */ private int textColor = Color.BLACK; private OnItemClickListener itemClickListener; private Context mContext; /** * 當前顯示Item的ID */ private volatile int currentId = -1; private CopyOnWriteArrayList<String> 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); } /** * 設置數(shù)據(jù)源 * * @param titles */ public void setTextList(ArrayList<String> 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<String> 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)); i--; newLine.setLength(0); } else { if (i == text.length() - 1) { lineList.add(newLine.toString()); newLine.setLength(0); break; } } } } textList.clear(); textList.addAll(lineList); currentId = -1; } /** * 開始輪播 */ 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); } /** * 停止輪播 */ 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, 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; } /** * 設置點擊事件監(jiān)聽 */ public void setOnItemClickListener(OnItemClickListener itemClickListener) { this.itemClickListener = itemClickListener; } /** * 輪播文本點擊監(jiān)聽器 */ public interface OnItemClickListener { /** * 點擊回調(diào) * * @param position 當前點擊ID */ public void onItemClick(int position); } }
關于php直播源碼如何實現(xiàn)TextView豎直滾動問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關知識。
當前題目:php直播源碼如何實現(xiàn)TextView豎直滾動
標題鏈接:http://sd-ha.com/article28/gddocp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站建設、企業(yè)網(wǎng)站制作、網(wǎng)站內(nèi)鏈、標簽優(yōu)化、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)