Showing posts with label Scrolling. Show all posts
Showing posts with label Scrolling. Show all posts

android:ellipsize - Make a Scrolling Marquee, using scrollHorizontally, in a TextView

How to Make a Scrolling Marquee, using scrollHorizontally, in a TextView

android:ellipsize was added in API Level 1
Related Method: setEllipsize - Make a Scrolling Marquee, using scrollHorizontally, in a TextView

1. Add a TextView.

2. Limit the number of lines and enable horizontal scrolling by adding scrollHorizontally to your TextView. 

    <TextView

        ...
        android:scrollHorizontally = "true"
    />


3. In the main.xml file, add the below line

  <TextView

    ....
       android:text="This is a really, really, really long line of text so you can see it scroll.This is a really, really, really long line of text so you can see it scroll."
      android:ellipsize = "marquee"
  />

4. If no other widgets are on the screen, this TextView will have focus by default, and will scroll automatically. However, if there are more widgets on the screen, when another widget gets focus, the scrolling will stop on the TextView because it has lost focus. To keep the focus on the TextView there are four options:

        a. add  
android:state_selected - Set Focus to a TextView, using state_selected, in XML

        b. add  requestFocus - Set Focus to a TextView, using requestFocus, in XML

        c. add setSelected(true) - Set Focus to a TextView, using Java

      d. add requestFocus - Set Focus to a TextView, using requestFocus, in Java

5. Compile and run!

Related Articles:
Resources:
http://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize
http://developer.android.com/reference/android/R.attr.html#ellipsize

Deprecated: android:singleLine - Set EditText to One Horizontally Scrolling Line

Deprecated: How to Set EditText to One Horizontally Scrolling Line, with finger

Deprecated in API Level 3, added in API Level 1
Use scrollHoriztonally instead for an EditText.

Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key.

1. Create an Android project, if you don't already have one.

2. Add an EditText in the main.xml file.

3. In the main.xml file, add the code below.

<EditText
        ...
       android:singleLine = "true"
/>

4. Compile and run!
http://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine
http://developer.android.com/reference/android/R.attr.html#singleLine