自动调整textview不起作用

时间:2017-10-07 09:53:07

标签: android

您好我在我的Android应用程序中使用autosize textview。我的app minSdkVersion是19,所以我使用的是支持库。

https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview.html

<?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="com.app.android.registration.RegistrationActivity"
    tools:ignore="missingPrefix">

    <include
        android:id="@+id/toolbar_registration_layout"
        layout="@layout/toolbar" />

    <TextView
        android:id="@+id/textview_registration_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="@font/lato_medium"
        android:padding="8dp"
        android:text="@string/registration_title"
        app:autoSizeTextType="uniform"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />


</android.support.constraint.ConstraintLayout>

enter image description here

有没有人知道为什么它没有调整大小,因为它右侧有很多空间。

2 个答案:

答案 0 :(得分:3)

在我的情况下,仅使用固定尺寸或match_parent无效。我必须添加“ maxLines = 1”和“ lines = 1”。不知道为什么在文档中没有对此做清楚说明。

答案 1 :(得分:2)

将您的android:layout_height="wrap_content"更改为特定值

赞: android:layout_height="200dp"

您可以阅读文档 - :

注意:如果您在XML文件中设置了自动调整大小,则不建议对wrap_contentlayout_width属性使用值“layout_height”一个TextView。它可能会产生意想不到的结果。

enter image description here

因此,您必须将固定值传递给 android:layout_height TextView

希望,这会对你有所帮助

相关问题