支持添加用于自动调整TextView的库

mtd*_*vem 5 android import-libraries android-layout android-support-library android-studio

我很困惑在Android Studio中添加正确的支持库以便能够使用AutoSizing TextViews. https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview.html
此页面上对使用哪些支持库的描述有点模糊.我试图导入建议的库,但要么我请求错误的库(找不到它们,例如android.support.v4.widget包)或者我正在做其他错误的操作.

我的最小SDK为21,最大SDK为27,因此如果我导入了正确的库,则AutoSizing功能应该向后兼容我的应用程序.但是,在屏幕设计视图中,我收到警告"属性autoSizeTextType仅用于API级别26及更高级别(当前最小值为21)"

据我所知,我有正确的支持库.项目结构依赖关系如下:

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'android.arch.lifecycle:compiler:1.0.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
implementation 'android.arch.persistence.room:compiler:1.0.0'
implementation 'android.arch.paging:runtime:1.0.0-alpha4-1'
implementation 'android.arch.core:core-testing:1.0.0'
implementation 'android.arch.persistence.room:testing:1.0.0'
implementation 'android.arch.lifecycle:common-java8:1.0.0'
implementation 'com.android.support:support-v13:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2-alpha1'
implementation 'com.android.support:support-annotations:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:preference-v14:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'android.arch.lifecycle:extensions:1.1.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.android.support:preference-v7:27.0.0'
implementation 'com.android.support:support-compat:27.0.0'
Run Code Online (Sandbox Code Playgroud)

有什么建议?我也可以使用一些链接来了解如何将建议的库转换为要导入的实际库.谢谢

编辑:部分布局列表与android:autoSizeTextType问题.我收到了列出的两个文本视图的警告消息.

<?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">

<android.support.constraint.Guideline
    android:id="@+id/guideline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintGuide_begin="134dp"/>

<android.support.v7.widget.AppCompatTextView
    android:id="@+id/temperature_label"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:text="@string/temperature"
    android:autoSizeTextType="uniform"
    app:layout_constraintEnd_toStartOf="@+id/guideline"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

<TextView
    android:id="@+id/temperature"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:hint="@string/temperature"
    android:autoSizeTextType="uniform"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toRightOf="@+id/guideline"
    app:layout_constraintTop_toTopOf="parent"/>
Run Code Online (Sandbox Code Playgroud)

编辑:我的解决方案现在.

我最终得到的这种布局似乎现在起作用了.不确定autoSizing是否正在调整大小,但这在我目前正在测试的设备上看起来不错.使用建议的autoSizeTextType的app:前缀尝试了纯文本视图,但是收到错误"Unexpected namespace prefix"app"找到标记TextView".当我将其更改为android.support.v7.widget.AppCompatTextView时,错误消失了.谢谢您的帮助.

<?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">

<android.support.constraint.Guideline
    android:id="@+id/guideline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintGuide_percent="0.38"/>

<android.support.v7.widget.AppCompatTextView
    android:id="@+id/temperature_label"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:text="@string/temperature"
    android:textAppearance="@style/TextAppearance.AppCompat.Large"
    app:autoSizeTextType="uniform"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

<android.support.v7.widget.AppCompatTextView
    android:id="@+id/temperature"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:hint="@string/temperature"
    android:textAppearance="@style/TextAppearance.AppCompat.Large"
    app:autoSizeTextType="uniform"
    app:layout_constraintLeft_toRightOf="@+id/guideline"
    app:layout_constraintTop_toTopOf="parent"/>
Run Code Online (Sandbox Code Playgroud)

Ben*_* P. 8

改变这个:

<android.support.v7.widget.AppCompatTextView
    android:autoSizeTextType="uniform"
    .../>
Run Code Online (Sandbox Code Playgroud)

对此:

<TextView
    app:autoSizeTextType="uniform"
    .../>
Run Code Online (Sandbox Code Playgroud)

没有必要AppCompatTextView直接引用.在LayoutInflater由支持库中使用自动注入程序兼容性的小部件来代替标准的部件.

此外,要在API-26之前进行自动调整大小,您需要使用支持库实现,这意味着您需要使用AppCompat属性(使用app:命名空间)而不是平台属性(使用android:命名空间).


Jéw*_*ôm' 6

尝试更改android:app:命名空间:

<android.support.v7.widget.AppCompatTextView
    app:autoSizeTextType="uniform"
    .../>
Run Code Online (Sandbox Code Playgroud)