How to replace ellipses with fade / fading edge in textview in Android sdk?

拜拜、爱过 提交于 2019-12-06 03:52:21

问题


I have a list, each row in the list has text. Some of the text extends beyond the edge of the screen. I have no problem making it truncate the text and show ellipses. I have no problem to 'fade the edge of the text' however, the fade occurs at the edge of every text, not just the ones the are too large for the textview. I have searched and searched and can't find a way to, essentially, do exactly what the ellipses do but, instead of ellipses, fade the edge of the text only if it is going off the edge of the screen. Can anyone please help? FYI, right now, my text view contains:

android:fadingEdge="horizontal" 
android:inputType="text"
android:maxLines="1"

but, obviously, I have tried many other things to no avail... :_(


回答1:


To enable marquee and simulateouly not affecting the list Selections Just use following:

In the code just use two methods on that text View.

textViewObj.setSelected(true);
textViewObj.setEllipsize(TextUtils.TruncateAt.MARQUEE);



回答2:


The specific method call to enable the horizontal edge fade (on the right-hand side) is

setHorizontalFadingEdgeEnabled(true)

Here is an example from the constructor in my class ScrollTextView, which extends TextView:

public ScrollTextView(Context context, AttributeSet attrs) {
    this(context, attrs, android.R.attr.textViewStyle);
    setHorizontalFadingEdgeEnabled(true);
}


来源:https://stackoverflow.com/questions/7489068/how-to-replace-ellipses-with-fade-fading-edge-in-textview-in-android-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!