Расположение ограничений на нескольких экранах - PullRequest
0 голосов
/ 14 апреля 2020

HI У меня проблема с макетами в android. Например, я проектирую этот макет с помощью Constraint Layout для Pixel 2 , он выглядит хорошо!

, но когда я перехожу на Nexus One 3.7, это пробелы исчезли, и я не хочу этого Nexus One 3.7

коды:

<?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:background="@color/dark"
    tools:context=".Fragment.Home.HomeFragment">

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/HomeAnimation"
        android:layout_width="match_parent"
        android:layout_height="140dp"
        android:layout_marginStart="85dp"
        android:layout_marginTop="60dp"
        android:layout_marginEnd="85dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:lottie_autoPlay="true"
        app:lottie_fileName="start.json"
        app:lottie_repeatCount="3" />

    <antonkozyriatskyi.circularprogressindicator.CircularProgressIndicator
        android:id="@+id/CircularProgress"
        android:layout_width="240dp"
        android:layout_height="240dp"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        app:direction="clockwise"
        app:dotColor="@color/white"
        app:dotWidth="18dp"
        app:drawDot="true"
        app:enableProgressAnimation="true"
        app:fillBackground="false"
        app:gradientEndColor="@color/green"
        app:gradientType="linear"
        app:layout_constraintBottom_toBottomOf="@+id/HomeAnimation"
        app:layout_constraintEnd_toEndOf="@+id/HomeAnimation"
        app:layout_constraintStart_toStartOf="@+id/HomeAnimation"
        app:layout_constraintTop_toTopOf="@+id/HomeAnimation"
        app:progressBackgroundColor="@color/progress_gray"
        app:progressBackgroundStrokeWidth="10dp"
        app:progressCap="round"
        app:progressColor="@color/red"
        app:progressStrokeWidth="16dp"
        app:startAngle="270" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/drowsinessScoreTextView"
        android:layout_width="15dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:text="0"
        android:textColor="@color/white"
        android:textSize="22sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/CircularProgress" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/MaxDrowsinessScoreTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="2dp"
        android:layout_marginLeft="2dp"
        android:layout_marginTop="2dp"
        android:fontFamily="@font/yekan"
        android:gravity="center"
        android:text="/5"
        android:textColor="@color/white"
        android:textSize="16sp"
        app:layout_constraintStart_toEndOf="@+id/drowsinessScoreTextView"
        app:layout_constraintTop_toTopOf="@+id/drowsinessScoreTextView" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/DrowsinessStringTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="-2dp"
        android:layout_marginEnd="28dp"
        android:layout_marginRight="28dp"
        android:fontFamily="@font/iranyekanmobilebold"
        android:gravity="center"
        android:text="@string/drowsiness"
        android:textColor="@color/white"
        android:textSize="16sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/drowsinessScoreTextView" />


    <androidx.appcompat.widget.AppCompatImageView
        android:layout_width="33dp"
        android:layout_height="33dp"
        android:layout_marginStart="12dp"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="12dp"
        android:src="@drawable/drowsinessicon"
        app:layout_constraintStart_toEndOf="@+id/MaxDrowsinessScoreTextView"
        app:layout_constraintTop_toTopOf="@+id/MaxDrowsinessScoreTextView" />

    <Chronometer
        android:id="@+id/MainChronometer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="60dp"
        android:layout_marginEnd="60dp"
        android:gravity="center"
        android:textColor="@color/white"
        android:textSize="55sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/DrowsinessStringTextView" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/StartButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="20dp"
        android:layout_marginBottom="25dp"
        android:background="@drawable/start_button_background"
        android:fontFamily="@font/iranyekanmobilemedium"
        android:text="@string/start"
        android:textColor="@color/white"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/StopButton"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:background="@drawable/stop_button_background"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/StartButton" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/StatusButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginBottom="25dp"
        android:background="@drawable/start_button_background"
        android:fontFamily="@font/iranyekanmobilemedium"
        android:text="وضعیت"
        android:textColor="@color/white"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

я читал это https://developer.android.com/training/multiscreen/screensizes раньше и попытался определить несколько макетов:

res/layout-small/main_activity.xml          
res/layout/main_activity.xml          
res/layout-large/main_activity.xml     
res/layout-xlarge/main_activity.xml

, но это не работает.

1 Ответ

0 голосов
/ 14 апреля 2020

Используемые классификаторы являются устаревшими и работают только в Android 3.1 и ниже. Используйте доступные квалификаторы высоты (-h600dp) или доступной ширины (-w600dp) или наименьшей ширины (-sw600dp).

...