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);
}
}
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android Service組件使用技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android仿zaker用手向上推動的特效開發(fā)【推動門效果】(附demo源碼下載)
這篇文章主要介紹了Android仿zaker用手向上推動的特效,結(jié)合完整實例形式分析了Android滑動切換效果的實現(xiàn)步驟與相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-07-07
Android中實現(xiàn)下載和解壓zip文件功能代碼分享
這篇文章主要介紹了Android中實現(xiàn)下載和解壓zip文件功能代碼分享,本文直接給出了實現(xiàn)代碼,需要的朋友可以參考下2015-03-03
Android標(biāo)題欄上添加多個Menu按鈕的實例
這篇文章主要介紹了Android標(biāo)題欄上添加多個Menu按鈕的實例的相關(guān)資料,這里提供簡單實例說明如何添加多個menu按鈕的方法,需要的朋友可以參考下2017-09-09
android工程下不能運行java main程序的解決方法
這篇文章主要介紹了android工程下不能運行java main程序的解決方法,需要的朋友可以參考下2014-05-05
Flutter?繪制風(fēng)車實現(xiàn)示例詳解
這篇文章主要為大家介紹了Flutter?繪制風(fēng)車實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
RecycleView實現(xiàn)item側(cè)滑刪除與拖拽
這篇文章主要為大家詳細(xì)介紹了RecycleView實現(xiàn)item側(cè)滑刪除與拖拽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-11-11

