android - 无法通过支持库使用自动调整 Textview
问题描述
我有以下文本视图,它应该包含自动调整大小的文本。
<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'
我使用这个文档作为我的指南。
我究竟做错了什么?
这是完整的布局:
<?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
为:
<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"
/>
这个答案对我来说没有意义,因为这篇文章中的第一个答案说我不应该这样做。但至少错误消失了。
推荐阅读
- android - 断言失败:第 6075 行 pos 12:'child == _child':不正确
- android - 如何在 React Native 应用程序中隐藏 index.android.bundle 中的敏感 API 密钥
- javascript - 使用 react-hooks-testing-library 进行测试时,自定义钩子的当前结果会更新
- c# - 添加记录器(serilog)后,我在响应中不再收到与 500 错误相关的错误消息
- javascript - 基于时间间隔的平滑图像移动?
- c# - newtonsoft 没有正确反序列化内部类中的双精度值
- java - 为什么它显示错误“从未使用分配的值”?
- window - 无法与 LXDE 中的窗口按钮交互
- javascript - React Bootstrap ButtonToolbar 不将按钮分开
- ios - 关于 Metal 中 alpha 的输出