当辅助功能选项更改时,TextView 自动调整缩减内容的大小

问题描述 投票:0回答:3

我有一个非常简单的启用自动调整大小的 TextView,文本字体大小会正确更改,直到我将设备字体大小(可访问性)更改为大或巨大,此时文本在视图底部被剪切,有什么解决办法吗?

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/txt_title"
        android:layout_width="0dp"
        android:layout_height="150dp"
        android:baselineAligned="false"
        android:ellipsize="end"
        android:gravity="start|center_vertical"
        android:maxLines="4"
        android:text="@string/lorem"
        app:autoSizeMaxTextSize="48sp"
        app:autoSizeMinTextSize="28sp"
        app:autoSizeTextType="uniform"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout> 

请注意,设置了固定高度 是为了显示 设置辅助功能选项 字体大小 时如何缩小文本 这是一些示例...

Default
字体大小:

Large
文字大小:

Huge
字体大小:

android textview accessibility
3个回答
1
投票

请将文本视图高度更改为“wrap_content”。


1
投票

您强制执行了 TextView 高度:

android:layout_height="150dp"

这不是明显的问题,除非字体足够大,4 行需要超过 150 dp 才能容纳。您需要重新考虑您的布局,最好摆脱固定高度。


0
投票

我遇到了这个问题并通过以下方法解决了:

android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="32dp"

并对开始、结束和顶部进行约束,而底部是可选的。

也尝试不同的 minHeight 。

© www.soinside.com 2019 - 2024. All rights reserved.