Android基于TextView不獲取焦點實現(xiàn)跑馬燈效果
本文實例講述了Android基于TextView不獲取焦點實現(xiàn)跑馬燈效果。分享給大家供大家參考,具體如下:
1. 寫一個類繼承TextView
package com.example.tt; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.TextView; public class ScrollingTextView extends TextView { public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public ScrollingTextView(Context context, AttributeSet attrs) { super(context, attrs); } public ScrollingTextView(Context context) { super(context); } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if(focused) super.onFocusChanged(focused, direction, previouslyFocusedRect); } @Override public void onWindowFocusChanged(boolean focused) { if(focused) super.onWindowFocusChanged(focused); } @Override public boolean isFocused() { return true; } }
2. xml 中增加屬性
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.example.tt.ScrollingTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="80dip" android:layout_marginBottom="25dip" android:textSize="25sp" android:singleLine="true" android:textColor="@android:color/black" android:ellipsize="marquee" android:focusable="true" android:marqueeRepeatLimit="marquee_forever" android:focusableInTouchMode="true" android:scrollHorizontally="true" android:text="這才是真正的文字跑馬燈效果,文字移動速度,文字移動方向,文字移動的樣式,動畫等等……" android:background="#2FFFFFFF" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout>
3. 在activity中聲明
package com.example.tt; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
更多關于Android相關內(nèi)容感興趣的讀者可查看本站專題:《Android Service組件使用技巧總結》、《Android編程之a(chǎn)ctivity操作技巧總結》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android操作SQLite數(shù)據(jù)庫技巧總結》、《Android操作json格式數(shù)據(jù)技巧總結》、《Android數(shù)據(jù)庫操作技巧總結》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
相關文章
Android仿zaker用手向上推動的特效開發(fā)【推動門效果】(附demo源碼下載)
這篇文章主要介紹了Android仿zaker用手向上推動的特效,結合完整實例形式分析了Android滑動切換效果的實現(xiàn)步驟與相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-07-07Android中實現(xiàn)下載和解壓zip文件功能代碼分享
這篇文章主要介紹了Android中實現(xiàn)下載和解壓zip文件功能代碼分享,本文直接給出了實現(xiàn)代碼,需要的朋友可以參考下2015-03-03android工程下不能運行java main程序的解決方法
這篇文章主要介紹了android工程下不能運行java main程序的解決方法,需要的朋友可以參考下2014-05-05RecycleView實現(xiàn)item側滑刪除與拖拽
這篇文章主要為大家詳細介紹了RecycleView實現(xiàn)item側滑刪除與拖拽,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-11-11