Android基于TextView不獲取焦點(diǎn)實(shí)現(xiàn)跑馬燈效果
本文實(shí)例講述了Android基于TextView不獲取焦點(diǎn)實(shí)現(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è)計(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)豎直滾動跑馬燈效果
- Android中使用TextView實(shí)現(xiàn)文字跑馬燈效果
- Android跑馬燈MarqueeView源碼解析
- android自定義View實(shí)現(xiàn)跑馬燈效果
- Android自定義可控制速度的跑馬燈
相關(guān)文章
百度語音識別(Baidu Voice) Android studio版本詳解
這篇文章主要介紹了百度語音識別(Baidu Voice) Android studio版本詳解的相關(guān)資料,需要的朋友可以參考下2016-09-09
Android自定義View實(shí)現(xiàn)水波紋擴(kuò)散效果
這篇文章主要為大家詳細(xì)介紹了Android如何通過自定義View實(shí)現(xiàn)水波紋擴(kuò)散效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2022-08-08
Android編程之匿名內(nèi)部類與回調(diào)函數(shù)用法分析
這篇文章主要介紹了Android編程之匿名內(nèi)部類與回調(diào)函數(shù)用法,結(jié)合實(shí)例形式分析了Android編程中所涉及的java匿名內(nèi)部類與回調(diào)函數(shù)的概念、定義、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-10-10
Android studio listview實(shí)現(xiàn)列表數(shù)據(jù)顯示 數(shù)據(jù)循環(huán)顯示效果
這篇文章主要介紹了Android studio listview實(shí)現(xiàn)列表數(shù)據(jù)顯示 數(shù)據(jù)循環(huán)顯示功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
Android ViewDragHelper完全解析 自定義ViewGroup神器
這篇文章主要為大家詳細(xì)介紹了Android ViewDragHelper完全解析,自定義ViewGroup神器,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03
Android實(shí)現(xiàn)多次閃退清除數(shù)據(jù)
這篇文章主要介紹了Android實(shí)現(xiàn)多次閃退清除數(shù)據(jù)的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-04-04

