国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android基于TextView不獲取焦點實現跑馬燈效果

2019-12-12 03:33:47
字體:
來源:轉載
供稿:網友

本文實例講述了Android基于TextView不獲取焦點實現跑馬燈效果。分享給大家供大家參考,具體如下:

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相關內容感興趣的讀者可查看本站專題:《Android Service組件使用技巧總結》、《Android編程之activity操作技巧總結》、《Android資源操作技巧匯總》、《Android文件操作技巧匯總》、《Android操作SQLite數據庫技巧總結》、《Android操作json格式數據技巧總結》、《Android數據庫操作技巧總結》、《Android開發入門與進階教程》、《Android視圖View技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 康乐县| 德兴市| 洛浦县| 林甸县| 滨州市| 蕲春县| 礼泉县| 临海市| 湖州市| 上高县| 万盛区| 平泉县| 深州市| 宝鸡市| 桂阳县| 定西市| 定远县| 津市市| 芒康县| 双流县| 六盘水市| 富平县| 措美县| 卢氏县| 阜新市| 彰化县| 通海县| 萨迦县| 申扎县| 香港 | 信阳市| 刚察县| 公安县| 内丘县| 西乌| 沂水县| 齐齐哈尔市| 永泰县| 搜索| 张家界市| 南昌市|