Android基于TextView不獲取焦點(diǎn)實(shí)現(xiàn)跑馬燈效果
本文實(shí)例講述了Android基于TextView不獲取焦點(diǎn)實(shí)現(xiàn)跑馬燈效果。分享給大家供大家參考,具體如下:
1. 寫(xiě)一個(gè)類繼承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="這才是真正的文字跑馬燈效果,文字移動(dòng)速度,文字移動(dòng)方向,文字移動(dòng)的樣式,動(dòng)畫(huà)等等……"
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ù)庫(kù)技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android 中TextView中跑馬燈效果的實(shí)現(xiàn)方法
- Android TextView實(shí)現(xiàn)跑馬燈效果的方法
- Android實(shí)現(xiàn)跑馬燈效果的方法
- Android自定義View實(shí)現(xiàn)豎直跑馬燈效果案例解析
- Android實(shí)現(xiàn)圖文垂直跑馬燈效果
- Android自定義textview實(shí)現(xiàn)豎直滾動(dòng)跑馬燈效果
- Android中使用TextView實(shí)現(xiàn)文字跑馬燈效果
- Android跑馬燈MarqueeView源碼解析
- android自定義View實(shí)現(xiàn)跑馬燈效果
- Android自定義可控制速度的跑馬燈
相關(guān)文章
Android仿zaker用手向上推動(dòng)的特效開(kāi)發(fā)【推動(dòng)門效果】(附demo源碼下載)
這篇文章主要介紹了Android仿zaker用手向上推動(dòng)的特效,結(jié)合完整實(shí)例形式分析了Android滑動(dòng)切換效果的實(shí)現(xiàn)步驟與相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
Android中實(shí)現(xiàn)下載和解壓zip文件功能代碼分享
這篇文章主要介紹了Android中實(shí)現(xiàn)下載和解壓zip文件功能代碼分享,本文直接給出了實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-03-03
Android動(dòng)態(tài)顯示具體到秒的相聚時(shí)間
這篇文章主要為大家詳細(xì)介紹了Android動(dòng)態(tài)顯示具體到秒的相聚時(shí)間,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
Android標(biāo)題欄上添加多個(gè)Menu按鈕的實(shí)例
這篇文章主要介紹了Android標(biāo)題欄上添加多個(gè)Menu按鈕的實(shí)例的相關(guān)資料,這里提供簡(jiǎn)單實(shí)例說(shuō)明如何添加多個(gè)menu按鈕的方法,需要的朋友可以參考下2017-09-09
Android高仿QQ6.0側(cè)滑刪除實(shí)例代碼
先給大家分享一下,側(cè)滑刪除,布局也就是前面一個(gè)item,然后有兩個(gè)隱藏的按鈕(TextView也可以),然后我們可以向左側(cè)滑動(dòng),然后顯示出來(lái),然后對(duì)delete(刪除鍵)實(shí)現(xiàn)監(jiān)聽(tīng),就可以了哈。好了那就來(lái)看看代碼怎么實(shí)現(xiàn)的吧2016-02-02
android工程下不能運(yùn)行java main程序的解決方法
這篇文章主要介紹了android工程下不能運(yùn)行java main程序的解決方法,需要的朋友可以參考下2014-05-05
Flutter?繪制風(fēng)車實(shí)現(xiàn)示例詳解
這篇文章主要為大家介紹了Flutter?繪制風(fēng)車實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
RecycleView實(shí)現(xiàn)item側(cè)滑刪除與拖拽
這篇文章主要為大家詳細(xì)介紹了RecycleView實(shí)現(xiàn)item側(cè)滑刪除與拖拽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11

