Android_textview's marquee effect

Source: Internet
Author: User

For Android controls in the TextView, I believe that everyone must be familiar with the text content is very convenient to display. However, I encountered a small problem when using, that is, when the text, how to show the user. Today we will introduce a solution----------the effect of the lantern.

First in order to achieve this effect, I visited a little Niang, get the answer is like this, seemingly solved, but there is a problem, first to show you the effect:

Code:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent"Android:layout_height= "Match_parent" android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Android:paddingbottom= "@dimen/activity_vertical_margin" tools:context= ". Mainactivity "android:orientation= "Vertical" > <TextView Android:text= "@string/text"android:textsize= "20SP"Android:singleline= "true"//Guaranteed text content line displayAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:ellipsize= "marquee" android:focusable= "true" android:focusableintouchmode= "true"Android:id= "@+id/textview1"/> <TextView Android:text= "@string/text"android:textsize= "20SP"Android:singleline= "true"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:ellipsize= "marquee" android:focusable= "true" android:focusableintouchmode= "true"Android:id= "@+id/textview2"/>
<LinearLayout>

The red label is for the vast number of users to provide solutions, the effect is how? The test shows that when only one TextView control is perfectly expected, the effect is no longer present when more than two TextView controls appear in view, so this solution is not perfect.

What is the cause of that? It is very simple, because when there are two TextView, one is selected by default, the other is not selected, so only one has this effect, and now provides a workaround for everyone:

Create a new Free_textview.java class file that inherits it to TextView, and then implement the three constructor methods of TextView without any modification.

Code:

 Packagecom.example.administrator.textview_new;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;ImportAndroid.widget.TextView;/*** Created by Administrator on 2015/2/3. * Custom TextView Controls*/ Public classFree_textviewextendstextview{ PublicFree_textview (Context context) {Super(context); }     PublicFree_textview (Context context, AttributeSet attrs) {Super(context, attrs); }     PublicFree_textview (context context, AttributeSet attrs,intDefstyle) {        Super(context, attrs, Defstyle); } @Override Public BooleanisFocused () {return true;//Be sure to set to true to ensure that all TextView are selected    }}

Layout file Code:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent"Android:layout_height= "Match_parent" android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Android:paddingbottom= "@dimen/activity_vertical_margin" tools:context= ". Mainactivity "android:orientation= "Vertical" > <Com.example.administrator.textview_new.free_TextView Android:text= "@string/text"android:textsize= "20SP"Android:singleline= "true"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:ellipsize= "Marquee"android:focusable= "true"Android:focusableintouchmode= "true"Android:id= "@+id/textview1"/> <Com.example.administrator.textview_new.free_TextView Android:text= "@string/text"android:textsize= "20SP"Android:singleline= "true"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:ellipsize= "Marquee"android:focusable= "true"Android:focusableintouchmode= "true"Android:id= "@+id/textview2"/></linearlayout>

Our marquee effect is even better here.

Android_textview's marquee effect

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.