【发布时间】: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