【问题标题】:text cropped android textView文本裁剪 android textView
【发布时间】:2018-04-19 12:23:51
【问题描述】:

我有 4 个文本视图,它们的大小取决于指南,指南的位置是正确的,因为它已经在整个项目中使用。我尝试了很多解决方案,但没有一个能帮助我解决我的问题。无论屏幕大小、字体大小或文本如何,我的文本总是被裁剪。

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

这是我正在寻找的结果。

这些文本视图是扩展 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" />

【问题讨论】:

  • 分享你的代码,展示你做了什么?
  • 添加你的代码和xml部分。

标签: android textview


【解决方案1】:

你需要给android:layout_height="wrap_content"的textview

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多