Rav*_*aha 5 android android-constraintlayout constraint-layout-chains
我将约束布局(android.support.constraint.ConstraintLayout)用作XML文件中的主要布局。当我们得到布局的两个视图时(一个用于用户视图,第二个用于拖放视图并提供它们之间的关系)。但是我只得到一个完全空白的窗口,如下所示:-
在我的布局中使用任何视图时出现此错误。请检查下图
我的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">
<ImageView
android:id="@+id/image_shot"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我已经尝试过以下解决方案,但是对我来说不起作用,请检查我搜索过的链接
请帮助我解决这个问题。谢谢
这是因为你没有constraint为付出任何ImageView。当您给予constraint时ImageView,该警告将被删除。
就像下面这样。
<?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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="25dp">
<ImageView
android:id="@+id/image_shot"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:src="@mipmap/ic_launcher"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
设置你的 gradle 如下。
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt' // for Databinding
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.hellokotlin"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android {
dataBinding {
enabled = true
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:25.4.0'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:recyclerview-v7:25.4.0'
kapt 'com.android.databinding:compiler:2.3.1' // for Databinding
}
Run Code Online (Sandbox Code Playgroud)
支持lib版本和buildToolsVersion
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.hellokotlin"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
implementation 'com.android.support:appcompat-v7:25.4.0'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5951 次 |
| 最近记录: |