我是Android Studio的新手,我一直在尝试使用Design Editor。我遵循this guide,并启用了“显示约束”,但在我的设计编辑器中,约束没有显示出来。而且,"Hello World“没有显示出来。我的问题是:为什么约束是不可见的,我不能向约束布局添加组件的原因是什么?
我使用的XML文件是Android studio中包含的'Basic Activity‘模板的默认值:
<?xml version="1.0" encoding="utf-8"?>
<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!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>我确实注意到在我的蓝图左上角的蓝图中,有一个非常小的方块,当我点击它时,它就是constraintlayout中的TextView。此外,在组件树中,注意到main (也是唯一的) constraintlayout被标记为以下错误:在com.android.support:design中资源@string/appbar_scrolling_view_behaviour被标记为私有。我不确定这是否与我的问题有关,因为这似乎是Google依赖项中的问题。
说到依赖关系,下面是我使用的build.gradle(Module:app)中的依赖关系:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.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'
}在过去的几天里,我一直在尝试解决这个问题,但我找不到有同样问题的帖子。如果有人能帮我一把,我将不胜感激。如果我设法修复它或在其他地方找到解决方案,我会在这里发布它。
发布于 2018-07-01 02:47:37
尝试使用稳定的库:
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'发布于 2018-07-01 02:45:33
好的,所以我找到了this post,在使用旧的支持依赖的情况下,描述了同样的问题。通过将支持依赖项从26.0.0-beta2降级到26.0.0-beta1,这个问题得到了解决。我使用的是28.0.0-alpha3,所以我想这对我没什么帮助。然而,似乎降级到28.0.0-alpha1解决了这个问题。
把这篇文章留给那些遇到同样问题的人。
https://stackoverflow.com/questions/51117404
复制相似问题