首页 > 解决方案 > Android 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/black"
    >


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="@id/logoGuideline"
        app:layout_constraintBottom_toBottomOf="@id/logoGuideline"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/myImage"/>

    <TextView
        android:id="@+id/info1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        app:layout_constraintTop_toBottomOf="@id/infoGuideline"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:textColor="@color/white"
        android:text="Hello World" />


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/logoGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.2"
        />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/infoGuideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.4"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

好行为 :

在此处输入图像描述

不良行为 :

在此处输入图像描述

在我看来,三星手机往往有不良行为......知道吗?

注意:偏好片段中包含的所有内容......这可能会影响渲染?

标签: androidandroid-constraintlayoutconstraintlayout-guideline

解决方案


推荐阅读