android - 迁移到 Androidx 后设计 View 和导入问题

标签 android android-constraintlayout

嗯,今天我终于在迁移到 Androidx 之后建立了一个项目(从一年前就停止了)。借助此页面的一些响应,我设法更改了所有命名空间,但要让我的项目 100% 运行,我仍然遇到两个问题。

第一个是设计 View 上的约束布局问题,我看不到我之前做过的任何事情。 第二个问题是一些我还没有更新的导入,Android Studio 仍然标记错误。

第一个问题

First Problem Image

第二个问题

Second Problem Image

为了以防万一,我现在将粘贴我的 gradle:

项目:

buildscript {

    repositories {
        google()
        jcenter()
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.example.usuario.tm"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test:runner:1.1.0-alpha3"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha3', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        implementation 'com.google.android.material:material:1.0.0'
        implementation 'com.google.gms:google-services:4.1.0'
        implementation 'com.google.android.gms:play-services-auth:16.0.1'
        testImplementation 'junit:junit:4.12'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'maven'

最佳答案

TabLayout 的正确导入是: 导入 com.google.android.material.tabs.TabLayout 它来自: 实现“com.google.android.material:material:1.0.0”

AppCompatActivity 的正确导入现在是 import androidx.appcompat.app.AppCompatActivity 来自 实现“androidx.appcompat:appcompat:1.0.0”

您还应该检查您的布局 xml。您需要使用命名空间声明约束布局:androidx.constraintlayout.widget.ConstraintLayout

您还应该尝试在此处删除遗留依赖项 implementation 'androidx.legacy:legacy-support-v4:1.0.0'

关于android - 迁移到 Androidx 后设计 View 和导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52961792/

相关文章:

android - bitmap.copy() 抛出内存不足错误

android - "SQLiteDiskIOException: error code 10: disk I/O error"在 DROP TABLE 上返回 ICS 和 Samsung Nexus

java - 创建通知 channel (React Native)

android - 更改覆盖 View 下方的图像的色调颜色

android - 为什么 ConstraintLayout 1.1.0 layout_constraintWidth_percent 和 layout_constraintDimensionRatio 不能一起工作?

android - 在 View 检查器中更新边距值对布局没有影响

android - 如何在 constraintlayout 中将 View 放置到与另一个 View 的特定偏移量

java - 如何将库导入到android项目中?

java - 如何使用 ConstraintLayout 创建此布局

java - 如何从 HTML 页面创建 Android 对话框?