TextView achieves the running lantern effect and textview implements the running lantern

Source: Internet
Author: User

TextView achieves the running lantern effect and textview implements the running lantern
TextView

I. Methods

Here we use two methods to achieve the effect of the running horse lamp, although it is essentially

The essence is:

1. TextView call out the running horse lamp Effect

2. Obtain the focus of TextView

 

First:

1. TextView call out the running horse lamp Effect

Android: ellipsize = "marquee"

2. Obtain the focus of TextView

Android: focusable = "true"
Android: focusableInTouchMode = "true"

Note:

In this way, if other widgets on the interface get the focus, the running horse lamp will be stopped.

 

Second:

1. TextView call out the running horse lamp Effect

Android: ellipsize = "marquee"

2. Obtain the focus of TextView

Public class MyTextView extends TextView {

Public boolean isFocused (){
Return true;
}

}

Our TextView uses fry. MyTextView.

Note:

Even if other programs get the focus, the running horse lamp will not stop.

 

Ii. code example

Ii. Code

Fry. MyTextView

 1 package com.example.textviewdemo; 2  3 import android.content.Context; 4 import android.util.AttributeSet; 5 import android.widget.TextView; 6  7 public class MyTextView extends TextView{ 8  9     public MyTextView(Context context, AttributeSet attrs, int defStyle) {10         super(context, attrs, defStyle);11         // TODO Auto-generated constructor stub12     }13 14     public MyTextView(Context context, AttributeSet attrs) {15         super(context, attrs);16         // TODO Auto-generated constructor stub17     }18 19     public MyTextView(Context context) {20         super(context);21         // TODO Auto-generated constructor stub22     }23     24     @Override25     public boolean isFocused() {26         return true;27     }28 }

/TextViewDemo1/res/layout/activity04.xml

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent" 5 android: orientation = "vertical"> 6 <TextView 7 android: id = "@ + id/TV _runHorseLamp" 8 android: layout_width = "match_parent" 9 android: layout_height = "wrap_content" 10 android: singleLine = "true" 11 android: ellipsize = "marquee" 12 android: focusable = "true" 13 Ndroid: focusableInTouchMode = "true" 14 android: text = "this is a long and mighty rolling section that achieves the effect of running the horse lamp. It has a very strong meaning and strong cultivation." 15/> 16 <! -- Ellipsize indicates the decimal point. marquee is used to add a scroll effect --> 17 <! -- Scroll only after obtaining the focus --> 18 19 <fry. myTextView20 android: id = "@ + id/TV _runHorseLamp1" 21 android: layout_width = "match_parent" 22 android: layout_height = "wrap_content" 23 android: ellipsize = "marquee" 24 android: singleLine = "true" 25 android: text = "this is a long and mighty rolling paragraph that achieves the effect of running the horse lamp. It has a very high definition and strong text" 26/> 27 28 29 <EditText30 android: id = "@ + id/et_1" 31 android: layout_width = "match_parent" 32 android: layout_height = "wrap_content" 33> 34 </EditText> 35 36 </LinearLayout>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.