Java Android为什么我在文本视图中的文本末尾有3个点

Java Android为什么我在文本视图中的文本末尾有3个点,java,android,Java,Android,我在我的android应用程序中使用本地化,并且在一些翻译中,文本不适合TextView,如果我没有指定它,它会在它的末尾添加三个点。我知道它这样做是因为文本不适合,但我没有指定它这样做。我正在尝试缩放文本以适应,但它不起作用,有人能告诉我为什么,它会在末尾添加三个点,而不是缩放以适应。我的代码适用于除两种语言之外不适合的所有其他文本 我可以上传代码,但在我余下的本地化过程中效果很好,我只是想知道为什么它会在末尾加上三个点?谢谢 编辑: 这是标题的自定义布局 XML: 在java类中,如果(re

我在我的android应用程序中使用本地化,并且在一些翻译中,文本不适合TextView,如果我没有指定它,它会在它的末尾添加三个点。我知道它这样做是因为文本不适合,但我没有指定它这样做。我正在尝试缩放文本以适应,但它不起作用,有人能告诉我为什么,它会在末尾添加三个点,而不是缩放以适应。我的代码适用于除两种语言之外不适合的所有其他文本

我可以上传代码,但在我余下的本地化过程中效果很好,我只是想知道为什么它会在末尾加上三个点?谢谢

编辑:

这是标题的自定义布局

XML:

在java类中,
如果(rect.width()>titleWidth)
允许进行缩放,那么它可以在任何地方工作,除了两种语言之外,在这两种语言中,rect width明显小于titleWidth,而实际上不然

尖叫声:

问题是文本视图左侧有红色的空间,我不想也不知道如何删除


他无法适应。如果要执行此操作,必须手动执行。您可以更改
ellipsize
属性以定义是否要查看。。。或者没有。

在xml文件中为该文本视图尝试此选项

android:scroll=“true”

或编程使用


setHorizontallyScrolling方法

用TextViewI显示layour layout.xml不,这是我的菜单如果你看java代码,我会考虑到这一点我刚刚在一款较小的老式手机上测试了它,很好,当菜单位于右上角时,它似乎就是nexus 5。我仍然不知道为什么它会在nexus 5的屏幕左侧增加边距,你能给我举个例子吗?现在我看到了一个类,它只是用来在textView中调整文本大小,但它非常庞大,我认为我不需要太多代码来在textView中缩放文本。我这样做的方式适用于所有其他本地化栏两种语言,整个应用程序中有两行文字无法正常工作。我还有一个问题,为什么我的文本视图不能显示在屏幕的最左侧,没有填充或边距,但即使我使用
android:layout\u alignParentLeft=“true”
,它也不会向左对齐,这是为什么呢?使用ellipsize的一个示例是:
android:ellipsize:start
关于对齐父对象左侧您必须看到存在TextView字段及其内容。如果要将内容向左对齐,应在其上施加重力。AlignParentLeft将字段置于左侧。因此,我所说的“左对齐”的意思是,即使我在运行应用程序时填充父对象,文本视图的左侧也总是有一些空间,我不知道为什么我可以显示屏幕截图
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/title_gradient"
android:orientation="vertical"
android:tag="title" >

<TextView
    android:id="@+id/title_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:singleLine="true"
    android:ellipsize="none"
    android:background="@color/solid_red"
    android:gravity="center"
    android:paddingBottom="3dp"
    android:text="@string/Hearing_Test"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/solid_white"
    android:textStyle="bold" />

<ImageButton
    android:id="@+id/info_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:background="#0000"
    android:padding="10dp"
    android:onClick="infoView"
    android:src="@drawable/info" >
</ImageButton>
<style name="MyCustomTheme" parent="Theme.Sherlock">
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarStyle" tools:targetApi="11">@style/MyActionBar</item>
    <item name="android:textCursorDrawable">@null</item>
</style>

<style name="MyActionBar" parent="@style/Widget.Sherlock.ActionBar">
    <item name="android:background" tools:targetApi="11">@drawable/title_gradient</item>
    <item name="background">@drawable/title_gradient</item>
    <item name="android:homeAsUpIndicator" tools:targetApi="11">@null</item>
    <item name="homeAsUpIndicator">@null</item>
    <item name="android:gravity">center</item>
</style>
public void setTitleTextSize(final int textId, final Boolean displayInfoButton){
    infoButton = ((Activity) context).findViewById(R.id.info_button);
    titleText = (TextView) ((Activity) context).findViewById(R.id.title_text);

    if(!displayInfoButton){
        infoButton.setVisibility(View.GONE);
    }

    ViewTreeObserver customTitleScale = titleText.getViewTreeObserver();

    customTitleScale.addOnPreDrawListener(new OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            final int infoWidth = infoButton.getMeasuredWidth();
            if(infoWidth !=0 || !displayInfoButton){
                ((Activity) context).runOnUiThread(new Runnable(){

                    @Override
                    public void run() {

                        if(Build.VERSION.SDK_INT >= 11.0){
                            TypedValue tv = new TypedValue();
                            ((Activity) context).getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
                            actionBarWidth = ((Activity) context).getResources().getDimensionPixelSize(tv.resourceId);
                        }

                        DisplayMetrics metrics = new DisplayMetrics();
                        Display Screen = ((Activity) context).getWindowManager().getDefaultDisplay();
                        Screen.getMetrics(metrics);
                        int screenWidth = metrics.widthPixels;

                        if(displayInfoButton){
                            titleWidth = screenWidth - infoWidth - actionBarWidth;
                        } else {
                            titleWidth = screenWidth - actionBarWidth;
                        }

                        titleText.setText(textId);
                        String text = ((Activity) context).getResources().getString(textId);
                        titleText.setMaxWidth(titleWidth);
                        Log.d("TextView Width", "Width: " + titleWidth);

                        TextPaint paint = titleText.getPaint();
                        Rect rect = new Rect();
                        int textLength = text.length();
                        paint.getTextBounds(text, 0, textLength, rect);
                        float width = rect.left + rect.right;
                        Log.d("Text length pixels", "Pixels " + width);


                        if(rect.width() > titleWidth){

                            float scale = (float) titleWidth / (float) rect.width();
                            float textSize = titleText.getTextSize();       
                            float scaleSize = (float) (textSize * (scale*0.8));     
                            titleText.setTextSize(TypedValue.COMPLEX_UNIT_PX, scaleSize);

                        }
                    }
                });
                infoButton.getViewTreeObserver().removeOnPreDrawListener(this);
            }
            return false;
        }
    });
}