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

首頁 > 系統 > Android > 正文

TextView實現跑馬燈效果 就這么簡單!

2019-12-12 02:18:52
字體:
來源:轉載
供稿:網友

一、方法

這里我們用兩種方法來實現跑馬燈效果,雖然實質上是一種

實質就是:

1、TextView調出跑馬燈效果

2、TextView獲取焦點 

第一種:

1、TextView調出跑馬燈效果

android:ellipsize="marquee"

2、TextView獲取焦點

android:focusable="true"
android:focusableInTouchMode="true"

說明:

這種方法如果界面上別的控件獲取焦點的時候就會停止這個跑馬燈效果 

第二種:

1、TextView調出跑馬燈效果

android:ellipsize="marquee"

2、TextView獲取焦點

public class MyTextView extends TextView{   public boolean isFocused() {    return true;  }}

我們的TextView用的就是fry.MyTextView

說明:

就算別的程序獲取焦點,這個跑馬燈效果也不會停止。 

二、代碼實例

效果圖

三、代碼

fry.MyTextView

package com.example.textviewdemo;import android.content.Context;import android.util.AttributeSet;import android.widget.TextView;public class MyTextView extends TextView{ public MyTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public MyTextView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public MyTextView(Context context) { super(context); // TODO Auto-generated constructor stub }  @Override public boolean isFocused() { return true; }}

/textViewDemo1/res/layout/activity04.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView  android:id="@+id/tv_runHorseLamp" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:text="這是一段很長的威武霸氣的滾動的實現跑馬燈效果的一段逼格很高的很有含義和涵養的文字" /> <!--ellipsize是小數點的意思 marquee 這句話是添加滾動效果--> <!-- 獲取焦點之后才能滾動 --> <fry.MyTextView android:id="@+id/tv_runHorseLamp1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:singleLine="true" android:text="這是一段很長的威武霸氣的滾動的實現跑馬燈效果的一段逼格很高的很有含義和涵養的文字" /> <EditText android:id="@+id/et_1" android:layout_width="match_parent" android:layout_height="wrap_content" > </EditText> </LinearLayout>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安康市| 余江县| 黄山市| 五指山市| 正宁县| 靖远县| 渭源县| 汝南县| 尼勒克县| 咸丰县| 徐闻县| 上林县| 绵阳市| 雷波县| 康马县| 瑞金市| 若尔盖县| 金湖县| 镇安县| 和田县| 自贡市| 石嘴山市| 邵阳市| 称多县| 香港| 临漳县| 嘉定区| 廉江市| 洛阳市| 招远市| 诸暨市| 六盘水市| 新营市| 临颍县| 台湾省| 阿尔山市| 泰安市| 镇平县| 宁波市| 武安市| 浪卡子县|