Java 未显示设置为0dp的约束布局文本视图宽度
我正在使用一本android简介书来设置一个约束布局,我认为我已经正确地完成了。预览看起来很完美,但当我运行它时,文本视图不会显示,只有图像视图 如果我将文本视图的宽度更改为“wrap_content”,它们会显示出来,但格式错误。这使我相信问题在于宽度为“0dp”。我不明白为什么会发生这种情况,我的xml与书本上的完全相同。任何对初学者的反馈都将不胜感激Java 未显示设置为0dp的约束布局文本视图宽度,java,android,xml,android-constraintlayout,Java,Android,Xml,Android Constraintlayout,我正在使用一本android简介书来设置一个约束布局,我认为我已经正确地完成了。预览看起来很完美,但当我运行它时,文本视图不会显示,只有图像视图 如果我将文本视图的宽度更改为“wrap_content”,它们会显示出来,但格式错误。这使我相信问题在于宽度为“0dp”。我不明白为什么会发生这种情况,我的xml与书本上的完全相同。任何对初学者的反馈都将不胜感激 <?xml version="1.0" encoding="utf-8"?> <android.support.const
<?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="wrap_content"
android:orientation="vertical"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="@+id/crime_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Crime Title"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/crime_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Crime Date"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/crime_title"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_solved"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"/>
</android.support.constraint.ConstraintLayout>
您是否解决了此问题?我也面临着同样的问题,我记不清了,但我想我缺少了一种依赖,或者可能是gradle的问题。尝试研究使用约束布局的需求,希望这会有所帮助。