安卓,使滚动视图溢出到左边,而不是正确的? [英] Android, make scrollable view overflow to the left instead of right?
问题描述
我使用的是父视图得到水平滚动就在我的TextView推荐:
I was recommended using a parent view to get horizontal scrolling right in my TextView:
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scrollHorizontally="true"
android:gravity="center|right"
android:text="123456789"/>
</HorizontalScrollView>
水平滚动正常工作,但它使内容溢出时,得到超过它的父的宽度正确的:
Horizontal scrolling works fine but it makes the content overflow to the right when it gets longer than it's parent's width:
-------
|123456|7
-------
不过我工作的一个TextView持有数和人数,因为通常靠右对齐,我需要的TextView溢出到对岸。 (你应该向左滚动看到字符串的开头)。
However I'm working on a textview that holds numbers and since numbers are commonly aligned to the right I need the textview to overflow to the opposite side. (you should have to scroll left to see the beginning of the string).
------
1|4567|
------
我已经试过比重=右和宽度的多种组合,但我不能设法做到这一点。我该如何调整文字的权利,并使其溢出到左侧?
I have tried multiple combinations of gravity="right" and widths but I cannot manage to do it. How can I align the text to the right and make it overflow to the left?
编辑:
我试图这样做,当用户键入:
I tried doing this when the user types:
calc.setText( newNumber );
HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hsv);
hsv.scrollTo(hsv.getRight(), hsv.getTop());
此滚动到右边每次一个数,然而最新的号码始终留出画面(它像它滚动,然后加入数)。
This scrolls to the right every time the user types a number, however the latest number is always left out of the screen (it's like it scrolled and THEN added the number).
推荐答案
我已经测试code。因此,有两种方法可以解决这个问题 第一个带有滚动条
I have tested the code . So there are two ways to get around this problem First one with ScrollBars
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hsv1);
hsv.scrollTo(hsv.getRight(), hsv.getTop());
}
},100L);
二是没有滚动条
Second one is without scrollBars
<TextView
android:ellipsize="start" //add this line
...
/>
这篇关于安卓,使滚动视图溢出到左边,而不是正确的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!