使用约束布局无法将文本视图放置在准则下方

时间:2019-12-23 10:53:21

标签: android android-layout android-constraintlayout

我正在尝试将TextView放在Guideline下面。我已经尝试过如下,

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
<TextView
    android:id="@+id/package_name_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/black"
    android:textSize="20sp"
    android:text="Package Name"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintTop_toBottomOf="@id/start_guideline"
    />
    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/start_guideline"
        android:layout_width="wrap_content"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        app:layout_constraintGuide_percent="0.05"/>
    <TextView
        android:id="@+id/sub_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Subscription"
        android:textColor="@color/black"
        android:textSize="15sp"
        app:layout_constraintTop_toBottomOf="@id/package_name_text_view"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

我的软件包名称TextView没有显示在“准则”下面...我是使用ConstraintLayout的新手。找不到我的错误...有人帮助我解决这个问题。

1 个答案:

答案 0 :(得分:1)

删除constraintTop_toTopOf in package_name_text_view

    <androidx.constraintlayout.widget.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <TextView
        android:id="@+id/package_name_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:textSize="20sp"
        android:text="Package Name"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/start_guideline"
        />


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/start_guideline"
        android:layout_width="wrap_content"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        app:layout_constraintGuide_percent="0.05"/>
    <TextView
        android:id="@+id/sub_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Subscription"
        android:textColor="@color/black"
        android:textSize="15sp"
        app:layout_constraintTop_toBottomOf="@id/package_name_text_view"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>