【问题标题】:Can't Use Autosizing Textview with Support Library无法通过支持库使用自动调整 Textview
【发布时间】:2018-06-04 22:17:16
【问题描述】:

我有以下文本视图,它应该包含自动调整大小的文本。

<TextView
    android:layout_width="0dp"
    android:layout_height="200dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@id/tabRecyclerView"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:background="@color/lightshade"
    android:text="@string/add_favorites_message"
    android:gravity="center"
    android:minLines="2"
    android:maxLines="2"
    app:autoSizeTextType="uniform"/>

但是,在引用最后一行时,我收到错误“意外的命名空间前缀“app””。

我觉得这很奇怪,因为我在 build.gradle 中使用了以下支持库:

implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'

我使用this documentation 作为我的向导。

我做错了什么?

这是完整的布局:

<?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="250dp"
    tools:context=".MainActivity">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/tabRecyclerView"
        android:layout_width="0dp"
        android:layout_height="50dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@id/imageRecyclerView"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/imageRecyclerView"
        android:layout_width="0dp"
        android:layout_height="200dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tabRecyclerView"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:background="@color/lightshade"
        />

    <TextView
        android:id="@+id/add_favorites_message"
        android:layout_width="0dp"
        android:layout_height="200dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tabRecyclerView"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:background="@color/lightshade"
        android:text="@string/add_favorites_message"
        android:visibility="gone"
        android:gravity="center"
        android:minLines="2"
        android:maxLines="2" />


</android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 您是否有任何其他布局包含您的 TextView 并在您的 ConstraintLayout 中您已经删除了 xmlns:app="schemas.android.com/apk/res-auto" ?
  • 我会发布完整的布局,但我相信不会。我认为问题不在于应用程序前缀本身,因为其他“应用程序”前缀工作正常。唯一有问题的是TextView 底部的那个启用自动调整大小的文本。
  • 你的 build.gradle 中的 targetSdkVersion 是什么?
  • 目标和编译sdk版本都是27
  • 真的很别扭。我知道这可能是一个愚蠢的建议,但是您是否尝试过清理和重建您的项目?

标签: android textview android-support-library support-v4


【解决方案1】:

我不得不将TextView 更改为:

<android.support.v7.widget.AppCompatTextView
    android:id="@+id/add_favorites_message"
    android:layout_width="0dp"
    android:layout_height="200dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@id/tabRecyclerView"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:autoSizeTextType="uniform"
    android:background="@color/lightshade"
    android:text="@string/add_favorites_message"
    android:visibility="gone"
    android:gravity="center"
    android:lines="2"
    />

这个答案对我来说没有意义,因为this 帖子中的第一个答案说我不应该这样做。但至少错误消失了。

【讨论】:

    猜你喜欢
    • 2012-08-25
    • 1970-01-01
    • 2013-07-16
    • 2014-11-02
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    相关资源
    最近更新 更多