Проблема с макетом ограничения - PullRequest
0 голосов
/ 27 января 2019

У меня значительная проблема, с которой я не сталкивался раньше.Я сделал то, что обычно делаю, работая с ограничениями.Не все мои поля поместятся на экране.Он хорошо работает на внешнем планшете.Ниже моя деятельностьосновная.Я также запустил его в линейной и относительной компоновке.Я могу Любая помощь будет оценена.

<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/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorBlack"
    tools:context=".MainActivity">

    <Spinner
        android:id="@+id/spCompany"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginBottom="468dp"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:spinnerMode="dropdown"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/rnumberText" />


    <TextView
        android:id="@+id/densityText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="7dp"
        android:background="@color/colorWhite"
        android:text=""
        android:visibility="gone"
        app:layout_constraintBottom_toTopOf="@id/strainerLabel"
        app:layout_constraintTop_toBottomOf="@+id/spCompany" />

    <TextView
        android:id="@+id/strainerLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:text="@string/strainer"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/strainerText"
        app:layout_constraintTop_toBottomOf="@+id/spCompany" />

    <TextView
        android:id="@+id/strainerText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="7dp"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:text=""
        android:textSize="30sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/spRatio"
        app:layout_constraintTop_toBottomOf="@+id/strainerLabel" />

    <Spinner
        android:id="@+id/spRatio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorWhite"
        android:spinnerMode="dropdown"
        app:layout_constraintBottom_toTopOf="@+id/enterweightLabel"
        app:layout_constraintTop_toBottomOf="@+id/strainerText" />

    <TextView
        android:id="@+id/rnumberText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="7dp"
        android:background="@color/colorWhite"
        android:text=""
        android:visibility="gone"
        app:layout_constraintBottom_toTopOf="@+id/spCompany"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="spread_inside" />

    <TextView
        android:id="@+id/catdensityText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorWhite"
        android:text=""
        app:layout_constraintBottom_toBottomOf="@+id/spRatio"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/spRatio" />

    <TextView
        android:id="@+id/enterweightLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:text="@string/enter_weight"
        android:textAlignment="center"
        android:textStyle="bold"
        android:visibility="visible"
        app:layout_constraintBottom_toTopOf="@+id/weightInput"
        app:layout_constraintTop_toBottomOf="@+id/spRatio" />

    <EditText
        android:id="@+id/weightInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="7dp"
        android:autofillHints="Enter Weight"
        android:background="@color/colorWhite"
        android:clickable="true"
        android:ems="10"
        android:focusable="true"
        android:gravity="center"
        android:imeOptions="actionDone"
        android:importantForAutofill="yes"
        android:inputType="numberDecimal"
        android:singleLine="true"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/totalcatLabel"
        app:layout_constraintTop_toBottomOf="@+id/enterweightLabel"
        tools:targetApi="o" />

    <TextView
        android:id="@+id/totalcatLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:text="@string/total_catalyst"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/totalcatText"
        app:layout_constraintTop_toBottomOf="@+id/weightInput" />

    <TextView
        android:id="@+id/totalcatText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="7dp"
        android:background="@color/colorWhite"
        android:clickable="false"
        android:gravity="center"
        android:text=""
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/totalweightLabel"
        app:layout_constraintTop_toBottomOf="@+id/totalcatLabel" />

    <TextView
        android:id="@+id/totalweightLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="@color/colorWhite"
        android:gravity="center"
        android:text="@string/total_weight"
        android:textSize="30sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/totalweightText"
        app:layout_constraintTop_toBottomOf="@+id/totalcatText" />

    <TextView
        android:id="@+id/totalweightText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="@color/colorWhite"
        android:gravity="center_horizontal|center_vertical"
        android:text=""
        android:textSize="60sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/calcButton"
        app:layout_constraintTop_toBottomOf="@+id/totalweightLabel" />

    <Button
        android:id="@+id/calcButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="@color/colorWhite"
        android:clickable="true"
        android:focusable="true"
        android:text="@string/calculate"
        android:visibility="visible"
        app:layout_constraintBottom_toTopOf="@+id/clearButton"
        app:layout_constraintTop_toBottomOf="@+id/totalweightText" />

    <Button
        android:id="@+id/clearButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorWhite"
        android:clickable="true"
        android:focusable="true"
        android:text="@string/Clear"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/calcButton" />


</android.support.constraint.ConstraintLayout>

enter image description here

Ответы [ 2 ]

0 голосов
/ 27 января 2019

Да, ваш контент занимает больше места, чем доступный, тогда ваш взгляд переполняет устройство.Использование ScrollView решит проблему с короткими экранами.

Вот как выглядит :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/root">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorBlack"
        tools:context=".MainActivity">

        <Spinner
            android:id="@+id/spCompany"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginBottom="468dp"
            android:background="@color/colorWhite"
            android:gravity="center"
            android:spinnerMode="dropdown"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/rnumberText" />


        <TextView
            android:id="@+id/densityText"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginBottom="7dp"
            android:background="@color/colorWhite"
            android:text=""
            android:visibility="gone"
            app:layout_constraintBottom_toTopOf="@id/strainerLabel"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/spCompany" />

        <TextView
            android:id="@+id/strainerLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:background="@color/colorWhite"
            android:gravity="center"
            android:text="@string/strainer"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/strainerText"
            app:layout_constraintTop_toBottomOf="@+id/spCompany" />

        <TextView
            android:id="@+id/strainerText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:background="@color/colorWhite"
            android:gravity="center"
            android:text=""
            android:textSize="30sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/spRatio"
            app:layout_constraintTop_toBottomOf="@+id/strainerLabel" />

        <Spinner
            android:id="@+id/spRatio"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorWhite"
            android:spinnerMode="dropdown"
            app:layout_constraintBottom_toTopOf="@+id/enterweightLabel"
            app:layout_constraintTop_toBottomOf="@+id/strainerText" />

        <TextView
            android:id="@+id/rnumberText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:background="@color/colorWhite"
            android:text=""
            android:visibility="gone"
            app:layout_constraintBottom_toTopOf="@+id/spCompany"
            app:layout_constraintEnd_toStartOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_chainStyle="spread_inside" />

        <TextView
            android:id="@+id/catdensityText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorWhite"
            android:text=""
            app:layout_constraintBottom_toBottomOf="@+id/spRatio"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/spRatio" />

        <TextView
            android:id="@+id/enterweightLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:background="@color/colorWhite"
            android:gravity="center"
            android:text="@string/enter_weight"
            android:textAlignment="center"
            android:textStyle="bold"
            android:visibility="visible"
            app:layout_constraintBottom_toTopOf="@+id/weightInput"
            app:layout_constraintTop_toBottomOf="@+id/spRatio" />

        <EditText
            android:id="@+id/weightInput"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:autofillHints="Enter Weight"
            android:background="@color/colorWhite"
            android:clickable="true"
            android:ems="10"
            android:focusable="true"
            android:gravity="center"
            android:imeOptions="actionDone"
            android:importantForAutofill="yes"
            android:inputType="numberDecimal"
            android:singleLine="true"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/totalcatLabel"
            app:layout_constraintTop_toBottomOf="@+id/enterweightLabel"
            tools:targetApi="o" />

        <TextView
            android:id="@+id/totalcatLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:background="@color/colorWhite"
            android:gravity="center"
            android:text="@string/total_catalyst"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/totalcatText"
            app:layout_constraintTop_toBottomOf="@+id/weightInput" />

        <TextView
            android:id="@+id/totalcatText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:background="@color/colorWhite"
            android:clickable="false"
            android:gravity="center"
            android:text=""
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/totalweightLabel"
            app:layout_constraintTop_toBottomOf="@+id/totalcatLabel" />

        <TextView
            android:id="@+id/totalweightLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:background="@color/colorWhite"
            android:gravity="center"
            android:text="@string/total_weight"
            android:textSize="30sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/totalweightText"
            app:layout_constraintTop_toBottomOf="@+id/totalcatText" />

        <TextView
            android:id="@+id/totalweightText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:background="@color/colorWhite"
            android:gravity="center_horizontal|center_vertical"
            android:text=""
            android:textSize="60sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toTopOf="@+id/calcButton"
            app:layout_constraintTop_toBottomOf="@+id/totalweightLabel" />

        <Button
            android:id="@+id/calcButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:background="@color/colorWhite"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/calculate"
            android:visibility="visible"
            app:layout_constraintBottom_toTopOf="@+id/clearButton"
            app:layout_constraintTop_toBottomOf="@+id/totalweightText" />

        <Button
            android:id="@+id/clearButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorWhite"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/Clear"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/calcButton" />


    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
0 голосов
/ 27 января 2019

Вы можете поместить свой ConstraintLayout в ScrollView

...