7

I am facing a problem of android:ellipsize that doesn't work in TextView. But to work well for android:singleLine.

I've heard that android:singleLine is "Deprecated", but it is not written in the reference in Android Developer.

https://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine

android:singleLine is no longer in the "Deprecated"?

ADDED: I solved this problem myself.

As it turns out, android:scrollHorizontally="true" of TextView's attribute is not reflected in xml file.

So, I tried to use setHorizontallyScrolling method, it worked.

*xml:*
<TextView
  android:id="@+id/text"
  android:ellipsize="end"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
/>

*code:*
TextView textView = (TextView)findViewByID(R.id.text);
textView.setHorizontallyScrolling(true);

but, I add "android:inputType="text" in xml like following, it doesn't work. Please be careful.

*xml:*
<TextView
  android:id="@+id/text"
  **android:inputType="text"**
  android:ellipsize="end"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
/>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
zaki
  • 71
  • 1
  • 4
  • Sorry ntc, I erased your answer by mistake. I tried android:maxLines="1", but did not work. I tried using android:maxLines="1" and android:scrollHorizontally="true", and I also use android:lines instead of android:maxLines, but did not work. – zaki Aug 11 '11 at 13:21
  • Possible duplicate of [Is the xml attribute singleLine deprecated or not in Android?](http://stackoverflow.com/questions/30028697/is-the-xml-attribute-singleline-deprecated-or-not-in-android) – bummi Dec 19 '16 at 05:41

2 Answers2

0

I am not sure if android:singleLine of TextView is nolonger in the “Deprecated”, because inside the deprecated constructor of TextView, there is a comment with regard to singleLine configuration..

// If set, the input type overrides what was set using the deprecated singleLine flag.

singleLine = !isMultilineInputType(inputType);

Source code: around 1156L of core/java/android/widget/TextView.java - platform/frameworks/base - Git at Google

Since Google leaves a comment saying that singleLine flag is deprecated, (although it is not written in the developer site) it may be so.

Community
  • 1
  • 1
Shawn
  • 51
  • 4
0

Try also setting the IME input to short text or something like that. it might work. there are a lot of issues with elipsize which i was also having at a point and didn't manage to solve. in my case it was connected to editTexts mostly and other components taking away the focus off the view. Focus is needed in order for Elipsize to work.

DArkO
  • 15,880
  • 12
  • 60
  • 88
  • Well unfortunately i don't think you will if there is anything grabbing the focus away. By the way i am assuming all the time that you want to achieve the marquee effect with it. I remember there being some examples where people use animation to do this ellipsize. – DArkO Aug 12 '11 at 06:11
  • Try these two links see where they lead: http://stackoverflow.com/questions/2160619/android-ellipsize-multiline-textview, http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll – DArkO Aug 12 '11 at 06:12
  • thanks DArkO. I solved this problem. android:scrollHorizontally="true" described in xml file is not reflected. Instead, I use "setHorizontallyScrolling" method, does worked. thank you! – zaki Aug 12 '11 at 09:32