Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-如何显示TextView的最后一部分_Android_Android Studio_Textview - Fatal编程技术网

Android-如何显示TextView的最后一部分

Android-如何显示TextView的最后一部分,android,android-studio,textview,Android,Android Studio,Textview,当一行文字过长时,如何使TextView始终显示其最后一部分 <HorizontalScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/display_sum" android:layout_width="match_parent

当一行文字过长时,如何使TextView始终显示其最后一部分

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <TextView
        android:id="@+id/display_sum"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="0.00"
        android:text=""
        android:textSize="50sp"
        android:textStyle="bold"

        android:layout_gravity="right"
        android:gravity="right"/>
    </HorizontalScrollView>

我想要这个:

不是这个:


在这种情况下,您必须设置

 android:ellipsize="start"
 android:singleLine="true"
您的文本视图应该

 <TextView
        android:id="@+id/textView"
        android:ellipsize="start"
        android:singleLine="true"
        android:text="very big text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


我想下面的代码可能会对您有所帮助

HorizontalScrollView horizontalScrollView = (HorizontalScrollView) findViewById(R.id.YourIdName)
horizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_FORWARD);
            //Observe for a layout change
            ViewTreeObserver viewTreeObserver = horizontalScrollView .getViewTreeObserver();
            if (viewTreeObserver.isAlive()) {
                viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        horizontalScrollView .fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                    }
                });
            }
        }

您所说的最终内容是什么意思?如果最终内容是指文本的最后一个单词或句子,请使用“android:ellipsize=“start”“@LearningAlways”,他指的是显示文本的最后一部分string@Vall0n我认为在这种情况下,它会
android:ellipsize=“end”
@InnerFire触发其中任何一个。但是我认为start意味着在textfield的开头显示椭圆(…)。如果我在TextView中加长文本,它可以正常工作。但当我缩短文本时,它会回到前面并逐渐后退。