我已经查询了前面的问题,但是没有一个使用现代的androidx版本的依赖项。为什么TextView无法自动调整文本大小?我已经指定了必需的依赖项(appcompat和legacy-support)。
如果我使用android:autoSizeMaxTextSize
而不是app:
可以使用,但是这需要API级别26,而我的目标是24。app:
曾经是androidx之前的后备方法;改变了吗?
我的build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.testprogram"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.leanback:leanback:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
和我的activity.xml
:
<FrameLayout 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:id="@+id/fullscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#330000"
tools:context=".MainActivity">
<TextView
android:id="@+id/textTimer1"
android:layout_width="893dp"
android:layout_height="415dp"
android:layout_marginStart="37dp"
android:layout_marginTop="-27dp"
android:alpha="0.25"
android:gravity="right|center_vertical"
android:maxLines="1"
android:text="Test Text"
android:textAlignment="gravity"
android:textColor="#ffffff"
android:textSize="380sp"
android:textStyle="bold"
app:autoSizeMaxTextSize="380sp"
app:autoSizeTextType="uniform" />
</FrameLayout>