Jetpack 撰写 1.1.1。 Modifier.align 已不存在
Jetpackcompose 1.1.1. Modifier.align doens't exist anymore
我已经将我的项目升级到 jetpack compose 1.1.1,连同 datastudio 的 Kotlin 1.6.10 和 7.1.2 升级。
从那时起,Android studio 在尝试使用 Modifier.align(..)
时会抛出错误。
我查了jpc的release notes,没找到align()贬值的信息。
不明白这里出了什么问题
没有 .align,项目构建良好,但我无法再对齐屏幕底部的按钮:-(
我的项目build.gradle
buildscript {
ext {
compose_version = '1.1.1'
nav_version = "2.4.1"
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的模块build.gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.jerome.jetpackcomposecrashcourse"
minSdk 29
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// navigation
implementation "androidx.navigation:navigation-compose:$nav_version"
}
可组合的 taht 之前没问题,但现在抛出错误
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
@Composable()
fun AddAlbumButton() {
val mainButtonColor = ButtonDefaults.buttonColors(backgroundColor = Color(247, 197, 33))
Button(
colors = mainButtonColor,
modifier = Modifier
.padding(24.dp)
.align(Alignment.BottomCenter) // <----- ERROR HERE
,
onClick = {
/*albums.add(
Album(
R.drawable.booksouls,
"book of souls",
"View details",
Font(R.font.font_book_of_souls, weight = FontWeight.ExtraBold),
fontSize = 16.sp
)
)*/
}
) {
Text(text = "Add one")
}
}
我刚刚使用 Jetpack Compose 1.0.1 版本尝试了您的代码,但它也无法正常工作。您可以将按钮包裹在 Column、Row 或 Box 中。
Box(
modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.BottomCenter
) {
Button(
modifier = Modifier
.padding(24.dp),
onClick = {
}
) {
Text(text = "Add one")
}
}
我已经将我的项目升级到 jetpack compose 1.1.1,连同 datastudio 的 Kotlin 1.6.10 和 7.1.2 升级。
从那时起,Android studio 在尝试使用 Modifier.align(..)
时会抛出错误。
我查了jpc的release notes,没找到align()贬值的信息。
不明白这里出了什么问题
没有 .align,项目构建良好,但我无法再对齐屏幕底部的按钮:-(
我的项目build.gradle
buildscript {
ext {
compose_version = '1.1.1'
nav_version = "2.4.1"
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的模块build.gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.jerome.jetpackcomposecrashcourse"
minSdk 29
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// navigation
implementation "androidx.navigation:navigation-compose:$nav_version"
}
可组合的 taht 之前没问题,但现在抛出错误
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
@Composable()
fun AddAlbumButton() {
val mainButtonColor = ButtonDefaults.buttonColors(backgroundColor = Color(247, 197, 33))
Button(
colors = mainButtonColor,
modifier = Modifier
.padding(24.dp)
.align(Alignment.BottomCenter) // <----- ERROR HERE
,
onClick = {
/*albums.add(
Album(
R.drawable.booksouls,
"book of souls",
"View details",
Font(R.font.font_book_of_souls, weight = FontWeight.ExtraBold),
fontSize = 16.sp
)
)*/
}
) {
Text(text = "Add one")
}
}
我刚刚使用 Jetpack Compose 1.0.1 版本尝试了您的代码,但它也无法正常工作。您可以将按钮包裹在 Column、Row 或 Box 中。
Box(
modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.BottomCenter
) {
Button(
modifier = Modifier
.padding(24.dp),
onClick = {
}
) {
Text(text = "Add one")
}
}