Android 文本视图文本未正确显示

Android 文本视图文本未正确显示,android,android-layout,android-canvas,textview,android-button,Android,Android Layout,Android Canvas,Textview,Android Button,我正在使用按钮和文本视图创建一个类似条形图的结构 我想在每个条上显示一些特定的值 如果值在4位以内,则会正确显示,但一旦5位数字出现,文本就会被包装,如下面的屏幕截图所示 我尝试了android:singleLine=“true”,但这并没有改变任何事情 布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android

我正在使用按钮和文本视图创建一个类似条形图的结构

我想在每个条上显示一些特定的值

如果值在4位以内,则会正确显示,但一旦5位数字出现,文本就会被包装,如下面的屏幕截图所示

我尝试了android:singleLine=“true”,但这并没有改变任何事情

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <SeekBar
        android:id="@+id/seekBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:maxHeight="9dp"
        android:minHeight="9dp"
        android:padding="10dp"
        android:max="100"
        android:progressDrawable="@drawable/seekbar_progress"
        android:thumb="@drawable/shine_btn" />

    <TextView
        android:id="@+id/tvValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:layout_alignRight="@id/seekBar"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="30dp" />

    <LinearLayout
        android:id="@+id/Graph01"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_below="@id/seekBar"
        android:layout_marginTop="50dp"
        android:gravity="bottom"
        android:orientation="vertical"
        android:weightSum="1" >

        <com.example.calci.views.MyTextView
            android:id="@+id/tvGraph01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="5dp" />        
        <Button
            android:id="@+id/btnGraph01"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="0.1"                        
            android:background="#99f" />                
    </LinearLayout>


    <LinearLayout
        android:id="@+id/Graph02"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_below="@id/seekBar"
        android:layout_marginTop="50dp"
        android:layout_toRightOf="@id/Graph01"
        android:gravity="bottom"
        android:orientation="vertical"
        android:weightSum="1" >

        <com.example.calci.views.MyTextView
            android:id="@+id/tvGraph02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="5dp" />

        <Button
            android:id="@+id/btnGraph02"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="0.1"
            android:background="#9f9" />
    </LinearLayout>

<!-- AND SO ON... -->
<RelativeLayout />
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromTouch) {
lp = new LinearLayout.LayoutParams(new ViewGroup.MarginLayoutParams(20,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    lp.setMargins(55, 0, 0, 0);
    tvGraph01.setLayoutParams(lp);
    tvGraph01.setTextSize(6);
    tvGraph01.setGravity(Gravity.CENTER);

    lp = new LinearLayout.LayoutParams(new ViewGroup.MarginLayoutParams(20,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    lp.setMargins(2, 0, 0, 0);
    tvGraph02.setLayoutParams(lp);
    tvGraph02.setTextSize(6);
    tvGraph02.setGravity(Gravity.CENTER);

lp = new LinearLayout.LayoutParams(20, 0, 0.0002f * 2 * progress * 20);
    lp.setMargins(55, 0, 0, 0);
    btnGraph01.setLayoutParams(lp);

    lp = new LinearLayout.LayoutParams(20, 0, 0.0002f * 2 * progress * 15);
    lp.setMargins(2, 0, 0, 0);
    btnGraph02.setLayoutParams(lp);
               }
    });

MyTextView

public class MyTextView extends TextView {
@Override
    protected void onDraw(Canvas canvas) {
        canvas.save();
// RORARING the textbox as I want to show text at right angle.
        canvas.rotate(270, getWidth() / 2, getHeight() / 2);
        super.onDraw(canvas);
        canvas.restore();
    }
}

我想这背后的主要原因是将textview的高度设置为20
我尝试增加textview的高度,但这增加了按钮之间的间距。
我尝试了各种重力值,但也不起作用

感谢您的帮助

编辑 1)。来自的任何内容。
android:singleLine=“true”
android:ellipsize=“end”
android:maxLines=“1”
对我的事业都不起作用,因为我不想把放到文本包装中。
我想显示全文

2)。除了增加所有按钮的高度外,将
android:layout_height=“300dp”
设置为
LinearLayout
没有任何区别

3)。设置
android:layout\u height=“150dp”
TextView
没有任何区别,因为我正在设置代码中的高度和宽度。

尝试以下操作:

您正在为
线性图
布局指定固定高度

与此相反:

android:layout_height="200dp"
使用以下命令:

android:layout_height="300dp" or
android:layout_height="wrap_content"
希望对你有帮助

谢谢。

试试这个:

您正在为
线性图
布局指定固定高度

与此相反:

android:layout_height="200dp"
使用以下命令:

android:layout_height="300dp" or
android:layout_height="wrap_content"
希望对你有帮助


谢谢。

更改建议的版面宽度和高度,然后检查是否可行

 android:layout_width="40px" 
android:layout_height="wrap_content"

更改可建议的布局宽度和高度,并检查是否可行

 android:layout_width="40px" 
android:layout_height="wrap_content"

将此添加到您的文本视图中

android:singleLine=“true” android:ellipsize=“end”


它将添加“…”如果文本数据不止一行,但请确保必须将TextView的宽度设置为某些值。如果需要将宽度保持为wrapcontent,请使用一些值设置填充。试试看

将此添加到您的文本视图中

Try this,

   android:layout_height="150dp"
   android:layout_width="wrap_content"
   android:maxLength="5"
android:singleLine=“true” android:ellipsize=“end”


它将添加“…”如果文本数据不止一行,但请确保必须将TextView的宽度设置为某些值。如果需要将宽度保持为wrapcontent,请使用一些值设置填充。试试看

需要进行一项重要更改:将
android:layout_-toRightOf=“@id/Graph01
inLinearLayout with id-Graph02更改为
android:layout_-toRightOf=“@id/tvGraph01”

Try this,

   android:layout_height="150dp"
   android:layout_width="wrap_content"
   android:maxLength="5"
i、 e.即使文本视图宽度增加,相应的线性布局也不会受到影响


另外,在增加代码中文本视图的宽度后,我必须为
tvGraph02
btnGraph02
等设置边距。

需要进行的一项重要更改:将
android:layout\u-toRightOf=“@id/Graph01
中带有id-Graph02的线性布局更改为
android:layout\u-toRightOf=“@id/tvGraph01”

i、 e.即使文本视图宽度增加,相应的线性布局也不会受到影响


另外,在增加代码中文本视图的宽度后,我必须为
tvGraph02
btnGraph02
等设置边距。

试试这个……增加android:layout\u marginRight=“10dp”Use
android:maxLines=“1”
@GAMA发布的解决方案的边距值?你的问题解决了吗?请检查更新的问题。试试这个…增加android:layout_marginRight=“10dp”Use
android:maxLines=“1”
@GAMA中的边距值你尝试过发布的解决方案吗?您的问题解决了吗?请检查更新的问题。请检查更新的问题。请检查更新的问题。请检查更新的问题。请检查更新的问题。请检查更新的问题。请检查更新的问题。请检查更新的问题。请检查更新的问题。