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

首頁 > 系統 > Android > 正文

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

2019-10-23 19:44:27
字體:
來源:轉載
供稿:網友

本文實例講述了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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通辽市| 石楼县| 中山市| 岳普湖县| 和平区| 汪清县| 大港区| 新巴尔虎左旗| 达拉特旗| 龙口市| 柏乡县| 财经| 宕昌县| 文水县| 潜江市| 南京市| 门头沟区| 阳信县| 石屏县| 望奎县| 日喀则市| 安国市| 长海县| 松原市| 榆中县| 漠河县| 什邡市| 茶陵县| 民县| 平定县| 吉木萨尔县| 女性| 溆浦县| 盐城市| 环江| 开阳县| 霍城县| 邵武市| 张北县| 和龙市| 彭阳县|