【问题标题】:Android Studio 3.1.3 having issues with Constraint layoutAndroid Studio 3.1.3 存在约束布局问题
【发布时间】:2023-03-10 17:59:01
【问题描述】:

我正在尝试在这里开始一个新项目,但出现了这个问题。我可以运行该项目并将其部署在模拟器中,但是这个渲染问题和使用私有资源让我失望。我已经尝试了互联网上所有可能的解决方案,但都无法解决问题

<?xml version="1.0" encoding="utf

<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"
   app:layout_behavior="@string/appbar_scrolling_view_behavior"
   tools:context=".MainActivity"
   tools:showIn="@layout/activity_main">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!" />

</android.support.constraint.ConstraintLayout>

风格

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>


</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

构建.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.acer.myapplication3"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
"android.support.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-jre7:$kotlin_version"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:28.0.0-alpha3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.2'
}

【问题讨论】:

  • 在这里发送你的xml文件源代码
  • @LearningAlways 在描述中添加了它
  • 您的问题不是渲染约束布局对吗?然后给你的 build.gradle。
  • @ShwetaChauhan 是的。每次创建新项目时,我都会收到渲染问题和使用私有资源消息。在描述中添加它。

标签: android android-studio android-studio-3.1.3


【解决方案1】:

遇到了同样的问题 - 前往 SDK 管理器并安装了其他 SDK 平台;奥利奥 8.1。似乎问题在于“新” API 28 仍然存在问题。它说部分安装,但我基本上只是检查了较低 API 的框并下载/安装:

此外,我更改了 build.gradle 文件的 SDK 版本、buildTools、appcompat 和设计版本,如下所示。它现在可以工作了,等这些问题得到解决后,我将回到 API 28。

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
    ...
    minSdkVersion 15
    targetSdkVersion 27
    ...

dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.0.0'
}

【讨论】:

  • 我觉得这个版本好像也有问题。我设法使用最新的金丝雀版本顺利开始了一个问题。不管怎样,我会告诉你们真正的问题是什么,我用谷歌创建了一个问题并向他们提出了错误。由于日程繁忙,我现在没有时间回复他们或执行他们建议的修复。无论如何感谢您的建议,我会在下周末尝试并更新结果。
  • 这应该是被接受的答案!我已将我的 gradle build 版本 8 更改为 7。它成功了!编码愉快!
【解决方案2】:

您只需从 build.gradle 文件的依赖项部分更改以下代码:

发件人:

implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'

收件人:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'

然后同步您的项目。

【讨论】:

  • 请不要将代码发布为图像。您应该将代码直接剪切并粘贴到您的答案中。
【解决方案3】:

我也有同样的问题。对我来说,原因是我的项目“自动转换第三方库以使用 AndroidXhas”。检查你的问题和我的一样吗?请按照here 中描述的两个步骤进行操作。

为了方便:

第一步: 请检查您的 gradle.properties,如果您看到以下行,您可能遇到与我完全相同的问题。您可以先删除它们。

android.useAndroidX=true
android.enableJetifier=true

第二步:在主要活动中,我改变了

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

进入

import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

突然间一切正常!

【讨论】:

  • 首先,如果你已经实现了androidX然后又被移除了,你必须要按照这两个步骤。谢谢朋友。
【解决方案4】:

尝试使用这个:

dependencies {
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.1'
}

而不是constraint-layout:1.1.2

这解决了我的问题。

【讨论】:

    【解决方案5】:

    添加“基地”。在'Theme.AppCompat.Light.DarkActionBar'之前 在 style.xml 中。 为我工作。

    【讨论】:

      【解决方案6】:
      1. 在左侧,点击应用。
      2. 然后,打开 res 文件夹。
      3. 打开 values 文件夹。
      4. 点击“styles.xml”文件夹。
      5. 将父变量更改为“Base.Theme.AppCompact.Light.DarkActionBar”

      【讨论】:

        【解决方案7】:

        确保您在 settings > gradle 中取消选中 OFF LINE 选项, 然后 联网后再次同步项目

        【讨论】:

          猜你喜欢
          • 2019-01-16
          • 1970-01-01
          • 2021-10-07
          • 1970-01-01
          • 2018-12-21
          • 1970-01-01
          • 1970-01-01
          • 2019-06-20
          相关资源
          最近更新 更多