ConstraintLayout 不放置视图,所有内容都堆叠在左上角

问题描述 投票:0回答:1

我正在尝试使用 ConstraintLayout 但每个视图都堆叠在左上角。无论我尝试什么,我都无法让图像视图位于右侧,即使存在约束,它仍然位于右侧和顶部。

我确实发现这个问题是相似的,尽管对他来说预览似乎有效,但一旦执行应用程序,他就会遇到麻烦。无论如何,那里没有任何有帮助的答案。

这是我的布局:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/crime_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Crime Title"
        app:layout_constraintBottom_toTopOf="@+id/crime_date"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/crime_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Crime Date"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/crime_title" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_solved"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

这是截图: screenshot

android android-studio android-constraintlayout
1个回答
0
投票

首先,您正在使用的 android studio 版本是什么。还可以尝试使用不同的布局寿命相对布局或线性布局,它也可能有效。

© www.soinside.com 2019 - 2024. All rights reserved.