在RecyclerView中自动调整TextView的大小会导致文本大小减小 [英] Autosizing TextViews in RecyclerView causes text size to decrease

查看:474
本文介绍了在RecyclerView中自动调整TextView的大小会导致文本大小减小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自动调整TextViews 在RecyclerView中,但是当我滚动几次时,文本变得很小,以至于显然无法正常工作.

I am trying to use Autosizing TextViews in a RecyclerView, but when I scroll a few times the text gets so small that it's obviously not working properly.

我的TextView示例:

Example of my TextView:

<android.support.v7.widget.AppCompatTextView
        android:id="@+id/textview_unit_title"
        android:layout_width="@dimen/tile_image_size"
        android:layout_height="wrap_content"
        android:maxLines="2"
        android:textSize="@dimen/medium_size"
        android:textColor="@color/color_text"
        android:paddingTop="@dimen/padding_title"
        android:layout_marginRight="2dp"
        android:layout_marginEnd="2dp"
        app:autoSizeMaxTextSize="@dimen/style_medium"
        app:autoSizeTextType="uniform"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toRightOf="@id/imageview_unit_icon"
        app:layout_constraintTop_toTopOf="parent"/>

我应该以编程方式在其他地方更新此缩放比例,还是有其他解决方案?

Should I update this scaling somewhere else programmatically or is there another solution?

推荐答案

自动调整TextViews

Android 8.0(API级别26)可让您指示TextView根据TextView的特征和边界自动扩大或缩小文本大小以填充其布局.

Android 8.0 (API level 26) allows you to instruct a TextView to let the text size expand or contract automatically to fill its layout based on the TextView's characteristics and boundaries.

注意:如果在XML文件中设置自动调整大小,则不建议使用值"wrap_content"作为layout_width或layout_heightTextView的属性.可能会产生意想不到的结果.

Note: If you set autosizing in an XML file, it is not recommended to use the value "wrap_content" for the layout_width or layout_height attributes of a TextView. It may produce unexpected results.

您应该限制高度

 android:layout_height="30dp"

这篇关于在RecyclerView中自动调整TextView的大小会导致文本大小减小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆