繁体   English   中英

文字裁剪android textView

[英]text cropped android textView

我有4个textview,它们的大小取决于准则,准则的位置是正确的,因为它已在整个项目中使用。 我尝试了许多解决方案,但没有一个可以帮助我解决问题。 无论屏幕大小,字体大小还是文本,我的文本总是被裁剪。

在此处输入图片说明

我寻找了根据容器的大小自动调整文本字段文本字体大小的选项,但对我而言不起作用。

这是我想要的结果。

在此处输入图片说明

这些textview是自定义textview,扩展了android.support.v7.widget.AppCompatTextView但到目前为止,尚未对文本本身进行任何修改。

编辑:这是我的自定义类

public class MyTextView extends android.support.v7.widget.AppCompatTextView {
    private Context context = null;
    private AttributeSet attrs = null;


    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

        this.context = context;
        this.attrs = attrs;

        setWillNotDraw(false);
        setIncludeFontPadding(false);
    }

    @Override
    public void onSizeChanged (int w, int h, int oldw, int oldh){
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}

这是XML

<android.support.constraint.Guideline
android:id="@+id/TopOf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.031200000000000002" />
                        <android.support.constraint.Guideline
android:id="@+id/StartOf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="0" />
                        <android.support.constraint.Guideline
android:id="@+id/BottomOf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.9062" />
                        <android.support.constraint.Guideline
android:id="@+id/EndOf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.16477" />
                        <com.customView.MyTextView
android:id="@+id/MyTextView"
android:fontFamily="roboto"

android:text="Downloads" 
android:textColor="#5d5d5d"
android:textSize="8dp"
app:autoSizeTextType="uniform"
android:textStyle="bold"
android:gravity="left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_constraintStart_toStartOf="@+id/StartOf"
app:layout_constraintTop_toTopOf="@+id/TopOf"
app:layout_constraintEnd_toEndOf="@+id/EndOf"
app:layout_constraintBottom_toBottomOf="@+id/BottomOf" />

您需要提供textview的android:layout_height="wrap_content"

<TextView android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:padding="5dp"
    android:text="text" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM