actually i have keep one scrollview. Inside that scroll view I set one textview at run time I want to set text in that textview. The string which I'm going to set is some what big in length so i could not get the string in a single line and i can get my string two or three lines. My scroll view layout width size is 250px. I dont want to exceed that size...My expectation is i want to see that string within that scrollview as single line if the string is exceeds the scroll size then it should horizontally scroll in text view. I tried some functions like setting horizontal scroll to scrollview and textview but nothing is work out. Pls help me how to solve this problem.
实际上我保留了一个scrollview。在滚动视图中,我在运行时设置了一个textview,我想在textview中设置文本。我要设置的字符串是一些大的长度,所以我无法将字符串放在一行中,我可以得到我的字符串两三行。我的滚动视图布局宽度大小为250px。我不想超过那个大小...我的期望是我想在滚动视图中看到该字符串作为单行,如果字符串超过滚动大小,那么它应该在文本视图中水平滚动。我尝试了一些功能,比如将水平滚动设置为scrollview和textview,但没有任何结果。请帮我解决这个问题。
urs,
s.kumaran.
5 个解决方案
#1
you have to use these two Xml attributes in your TextView widget:
您必须在TextView小部件中使用这两个Xml属性:
android:scrollHorizontally="true"
android:singleLine="true"
So your xml layout must contain something like this:
所以你的xml布局必须包含这样的东西:
<TextView
android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
you can get the correspondant method for these attributes if you are creating Your TextView with code, refer to TextView documentation :
如果要使用代码创建TextView,可以获取这些属性的对应方法,请参阅TextView文档:
setHorizontallyScrolling(boolean)
setTransformationMethod(TransformationMethod)
setMarqueeRepeatLimit(int)
#2
try this ,,
试试这个 ,,
TextView.setHorizontallyScrolling(true) TextView.setLines(1);
where did you add the textview..Inside scrollview we able to add only one view...
你在哪里添加了textview..Inside scrollview我们只能添加一个视图...
#3
Take TextView and HorizontalScrollView. Just put textview inside the HorizontalScrollView. And yes make sure to mentioned android:singleLine="true"
inside the TextView.
使用TextView和HorizontalScrollView。只需将textview放在HorizontalScrollView中。是的,确保在TextView中提到android:singleLine =“true”。
#4
I had the same issue with a TextView inside a table and nothing detailed here solved the fact that it wouldn't scroll horizontally (automatically, which might not be the desired effect from OP, but it's quite unclear).
我在表格中遇到了与TextView相同的问题,这里没有详细说明解决了它不会水平滚动的事实(自动,这可能不是OP所期望的效果,但它还不太清楚)。
While comparing some code that did work, I found out the TextView must be selected for scrolling to start:
在比较一些有效的代码时,我发现必须选择TextView才能开始滚动:
TextView text_view = new TextView(context);
text_view.setLines(1);
text_view.setHorizontallyScrolling(true);
text_view.setMarqueeRepeatLimit(-1); // At this point the view is not scrolling!
...
text_view.setSelected(true); // Get scrolling to start
Seems crazy, but it works.
看起来很疯狂,但它确实有效。
#5
for me, this one line in the EditText xml was enough:
对我来说,EditText xml中的这一行就足够了:
android:singleLine="true"
#1
you have to use these two Xml attributes in your TextView widget:
您必须在TextView小部件中使用这两个Xml属性:
android:scrollHorizontally="true"
android:singleLine="true"
So your xml layout must contain something like this:
所以你的xml布局必须包含这样的东西:
<TextView
android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
you can get the correspondant method for these attributes if you are creating Your TextView with code, refer to TextView documentation :
如果要使用代码创建TextView,可以获取这些属性的对应方法,请参阅TextView文档:
setHorizontallyScrolling(boolean)
setTransformationMethod(TransformationMethod)
setMarqueeRepeatLimit(int)
#2
try this ,,
试试这个 ,,
TextView.setHorizontallyScrolling(true) TextView.setLines(1);
where did you add the textview..Inside scrollview we able to add only one view...
你在哪里添加了textview..Inside scrollview我们只能添加一个视图...
#3
Take TextView and HorizontalScrollView. Just put textview inside the HorizontalScrollView. And yes make sure to mentioned android:singleLine="true"
inside the TextView.
使用TextView和HorizontalScrollView。只需将textview放在HorizontalScrollView中。是的,确保在TextView中提到android:singleLine =“true”。
#4
I had the same issue with a TextView inside a table and nothing detailed here solved the fact that it wouldn't scroll horizontally (automatically, which might not be the desired effect from OP, but it's quite unclear).
我在表格中遇到了与TextView相同的问题,这里没有详细说明解决了它不会水平滚动的事实(自动,这可能不是OP所期望的效果,但它还不太清楚)。
While comparing some code that did work, I found out the TextView must be selected for scrolling to start:
在比较一些有效的代码时,我发现必须选择TextView才能开始滚动:
TextView text_view = new TextView(context);
text_view.setLines(1);
text_view.setHorizontallyScrolling(true);
text_view.setMarqueeRepeatLimit(-1); // At this point the view is not scrolling!
...
text_view.setSelected(true); // Get scrolling to start
Seems crazy, but it works.
看起来很疯狂,但它确实有效。
#5
for me, this one line in the EditText xml was enough:
对我来说,EditText xml中的这一行就足够了:
android:singleLine="true"