ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Androidx错误膨胀视图

2019-09-10 15:34:34  阅读:322  来源: 互联网

标签:android-ktx android androidx android-jetpack kotlin


我正在尝试使用Androidx.该应用程序非常新,因此代码不多.我确实在android studio中使用了“Refactor to Androidx”选项.但在那之后的某个时候,它停止了工作.我不知道是什么让它停止工作.

我应该做些什么?

但它得到了这个错误

Error inflating class androidx.constraintlayout.widget.ConstraintLayout

主要活动

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        pick_image.setOnClickListener {
            toast("Pick image clicked")
        }

    }
}

XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/pick_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="Pick image"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

build.gradle(app)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.alvarlagerlof.blurr"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // Androidx
    implementation 'androidx.core:core-ktx:1.0.0-alpha3'
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'


    // Testing
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
}

解决方法:

编辑2:自新版本以来,他们又回到了androidx.constraintlayout.widget.ConstraintLayout.
如果您正在使用约束布局版本1.1.1,请继续阅读

编辑:作为Arturo Mejia’s answer,只需按⇧⌘R或Ctrl Shift R即可

替换任何

androidx.constraintlayout.widget.ConstraintLayout

androidx.constraintlayout.ConstraintLayout

在使用Constraint Layout的所有XML文件中.

这是自约束布局版本v1.1.1以来的一个变化(在v1.1.0中,ConstraintLayout类仍在“.widget”包内)

旧的解决方法答案:

Change from

implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

to

implementation 'androidx.constraintlayout:constraintlayout:1.1.0'

I tried to press Command + Click at ConstraintLayout in
androidx.constraintlayout.widget.ConstraintLayout from XML file to
show the original class but it doesn’t find any thing. After I edited
the constraint layout version to 1.1.0 then it’s there.

标签:android-ktx,android,androidx,android-jetpack,kotlin
来源: https://codeday.me/bug/20190910/1799457.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有