简体   繁体   English

文字裁剪android textView

[英]text cropped android textView

I got 4 textview, their size depends on guidelines, the placement of the guidelines is correct since it's already used all over the project. 我有4个textview,它们的大小取决于准则,准则的位置是正确的,因为它已在整个项目中使用。 I tried many solutions but none of them helped me solving my problem. 我尝试了许多解决方案,但没有一个可以帮助我解决问题。 My text is always cropped, no matter the size of the screen, the font size or the text. 无论屏幕大小,字体大小还是文本,我的文本总是被裁剪。

在此处输入图片说明

I looked for options that auto resize textfield text's font depending on the size of the container but it didn't worked for me. 我寻找了根据容器的大小自动调整文本字段文本字体大小的选项,但对我而言不起作用。

Here is the result I am looking for. 这是我想要的结果。

在此处输入图片说明

those textviews are custom textview extending android.support.v7.widget.AppCompatTextView but no modification is done to the text itself so far. 这些textview是自定义textview,扩展了android.support.v7.widget.AppCompatTextView但到目前为止,尚未对文本本身进行任何修改。

EDIT : here is my custom class 编辑:这是我的自定义类

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);
    }
}

here is the xml 这是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" />

You need to give android:layout_height="wrap_content" of textview 您需要提供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