Simple implementation of TextView single-line text horizontal touch sliding effect, textview

Source: Internet
Author: User

Simple implementation of TextView single-line text horizontal touch sliding effect, textview

Recently I used TextView as a single-President text. When the text content is too long, I want to achieve horizontal sliding of the touch. I found a lot on the Internet and did not see any effective solutions.

Among them, the most common is the most clumsy use of override TextView and inherit to implement touch and Gesture gestures.

Later I was reminded to find the simplest solution:

Simply use EditText.Because edittext needs to edit and move the cursor, it can slide horizontally. Therefore, we only need to set it as a transparent background and do not obtain the focus. (Note: editable = "false" cannot be used, because it cannot be edited and slide. By using focusable = "false", you can also slip without editing.) Here, we will record it and give you some inspiration. You don't have to use your own smart methods to do the most stupid things. Mutual encouragement.

<EditText android: id = "@ + id/text_view" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: singleLine = "true" android: textSize = "20dip" android: textColor = "# fff" android: focusable = "false" android: background = "@ android: color/transparent" android: text = "ah, I'm hungry. I'm Oh Fei, I'm flying, I'm going to fly, and I'm going to fly. emma "/>


I will post some tutorials on the back, which can be ignored: (the following content is not original, forgive me)


1. What should I do if I only want TextView to display a row, but the text exceeds the length of TextView?
Show ellipsis at the beginning
Android: singleLine = "true"
Android: ellipsize = "start"


Show ellipsis at the end
Android: singleLine = "true"
Android: ellipsize = "end"


Show ellipsis in the middle
Android: singleLine = "true"
Android: ellipsize = "middle"


Automatic horizontal scrolling (running horse light effect)
Android: singleLine = "true"
Android: ellipsize = "marquee"
Android: marqueeRepeatLimit = "marquee_forever"
Android: focusable = "true"
Android: focusableInTouchMode = "true"


Android: singleLine = "true" must be added to all the above four effects, because TextView will automatically wrap by default.


Android: ellipsize indicates how to display long text


Android: marqueeRepeatLimit = "marquee_forever" indicates that the settings are always repeated. You can also set specific numbers.


Android: focusable = "true" and android: focusableInTouchMode = "true" must be added. Otherwise, the rolling effect will fail.


2. How can I make TextView scroll vertically?
Add the following sentence to the Java code to implement vertical scrolling.

TextView. setMovementMethod (ScrollingMovementMethod. getInstance ());


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.