多屏约束布局

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

嗨,我在android中的布局有问题,例如我使用Pixel 2的约束布局设计了此布局it looks fine!

但是当我改用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

但不起作用。

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

使用的那些限定符是旧式限定符,仅在Android 3.1及以下版本中有效。使用可用的高度(-h600dp)或可用的宽度(-w600dp)或最小宽度(-sw600dp)限定符。


0
投票

未获得dp尺寸的尺寸。尝试使用wrap_content或match_parent并在约束布局中尝试设置组件位置。无论如何,您肯定会在较小的屏幕中拥有较小的空间。

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