如何实现小屏幕和大屏幕尺寸的响应式布局?

时间:2017-12-08 15:04:01

标签: android android-layout android-constraintlayout android-layout-weight

我在适当缩放布局方面遇到了问题。

这是我的布局:

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_marginTop="@dimen/margin_large"
    android:layout_marginLeft="@dimen/margin_xlarge"
    android:layout_marginRight="@dimen/margin_xlarge">

    <include
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout="@layout/commissioning_progress_component" />
    <com.app.widget.StepProgressArrow
        android:id="@+id/progress_arrow_asset_to_sync"

        android:layout_width="match_parent"
        android:layout_height="@dimen/progress_arrow_size"

        app:startColor="@color/circular_progress_middle_color"
        app:endColor="@color/circular_progress_end_color"
        android:gravity="right"/>

    <com.app.widget.StepProgressArrow
        android:id="@+id/progress_arrow_sync_to_params"

        android:layout_width="@dimen/progress_arrow_size"
        android:layout_height="match_parent"

        app:startColor="@color/circular_progress_middle_color"
        app:endColor="@color/circular_progress_end_color"
        android:gravity="bottom"  />

    <com.app.widget.StepProgressArrow
        android:id="@+id/progress_arrow_params_to_completed"
        android:layout_width="match_parent"
        android:layout_height="@dimen/progress_arrow_size"

        app:startColor="@color/circular_progress_middle_color"
        app:endColor="@color/circular_progress_end_color"
        android:gravity="left" />

    <TextView
        android:id="@+id/progress_text_stage_params"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        style="@style/AppWidget.Text.Emphasized"
        android:gravity="center"
        android:textColor="@color/circular_progress_middle_color"
        android:text="@string/msg_in_store_commissioning_stage_params" />


</FrameLayout>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/commissioning_upload_info"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_marginRight="@dimen/margin_normal"
            android:layout_marginTop="@dimen/margin_normal"

            android:gravity="center"
            style="@style/AppWidget.Text.Gray.XSmall"
            android:text="@string/msg_commissioning_cloud_upload_info"
            android:visibility="gone"
            tools:visibility="visible" />

        <Button
            android:id="@+id/button_back_to_device_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_marginRight="@dimen/margin_normal"
            android:layout_marginTop="@dimen/margin_small"
            android:layout_marginBottom="@dimen/margin_small"

            android:text="@string/button_back_to_device_list"
            android:visibility="gone"
            tools:visibility="visible"
            style="@style/AppWidget.Button"/>

        <TextView
            android:id="@+id/cloning_finished_info"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_marginRight="@dimen/margin_normal"
            android:layout_marginTop="@dimen/margin_normal"

            style="@style/AppWidget.Text.Gray.Medium"
            android:text="@string/new_controller_installed"
            android:visibility="gone"
            tools:visibility="visible" />

        <Button
            android:id="@+id/button_continue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_marginRight="@dimen/margin_normal"
            android:layout_marginTop="@dimen/margin_small"
            android:layout_marginBottom="@dimen/margin_small"
            android:layout_gravity="right"

            android:paddingLeft="@dimen/margin_normal"
            android:paddingRight="@dimen/margin_normal"
            android:text="@string/button_continue"
            android:visibility="gone"
            tools:visibility="visible"
            style="@style/AppWidget.Button.Green"/>

    </LinearLayout>

    <TextView
        android:id="@+id/sync_time_left_text"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="@dimen/margin_small"

        style="@style/AppWidget.Text.Gray.Medium"
        android:gravity="center"
        android:visibility="gone"
        android:padding="@dimen/margin_small"
        android:background="@drawable/box"

        tools:visibility="visible"
        tools:text="Time left 5s"/>

</FrameLayout>

以下是我所包含的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">


<com.app.widget.CircularColorProgressView
    android:id="@+id/progress_stage_asset"
    android:layout_width="@dimen/circular_color_progress_size_small"
    android:layout_height="@dimen/circular_color_progress_size_small"
    android:layout_marginStart="24dp"
    app:hideText="true"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:skipStartColor="true" />

<TextView
    android:id="@+id/progress_text_stage_asset"

    style="@style/AppWidget.Text.Emphasized"
    android:layout_width="wrap_content"

    android:layout_height="wrap_content"
    android:layout_marginStart="22dp"
    android:layout_marginTop="12dp"

    android:gravity="center"
    android:text="@string/msg_in_store_commissioning_stage_asset"
    android:textColor="@color/circular_progress_middle_color"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/progress_stage_asset"
    app:layout_gravity="center_horizontal"
    />

<com.app.widget.CircularColorProgressView
    android:id="@+id/progress_stage_sync"
    android:layout_width="@dimen/circular_color_progress_size_small"
    android:layout_height="@dimen/circular_color_progress_size_small"
    android:layout_marginEnd="10dp"

    app:hideText="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:skipStartColor="true" />

<TextView
    android:id="@+id/progress_text_stage_sync"
    style="@style/AppWidget.Text.Emphasized"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/margin_small"
    android:gravity="center"
    android:text="@string/msg_in_store_commissioning_stage_sync"
    android:textColor="@color/circular_progress_middle_color"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/progress_stage_sync"
    app:layout_gravity="center_horizontal" />

<com.app.widget.CircularColorProgressView
    android:id="@+id/progress_stage_completed"

    android:layout_width="@dimen/circular_color_progress_size_medium"
    android:layout_height="@dimen/circular_color_progress_size_medium"

    android:layout_marginBottom="48dp"


    app:hideText="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_gravity="center_horizontal"
    app:skipStartColor="true" />

<TextView
    android:id="@+id/progress_text_stage_completed"

    style="@style/AppWidget.Text.Emphasized"
    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_marginStart="3dp"
    android:layout_marginTop="@dimen/margin_small"
    android:gravity="center"
    android:text="@string/msg_in_store_commissioning_stage_completed"
    android:textColor="@color/circular_progress_middle_color"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/progress_stage_completed"
    app:layout_gravity="center_horizontal" />

<com.app.widget.CircularColorProgressView
    android:id="@+id/progress_stage_params"
    android:layout_width="@dimen/circular_color_progress_size_small"
    android:layout_height="@dimen/circular_color_progress_size_small"
    android:layout_marginBottom="72dp"
    android:layout_marginEnd="10dp"
    app:hideText="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:skipStartColor="true" />

所以这就是包含布局的样子,它适用于每个屏幕(从3.7到6.0): enter image description here

这是缩放整个布局的问题。 这是它寻找屏幕6.0的方式: enter image description here

这是屏幕3.7的问题 enter image description here

那么如何正确扩展我的布局呢?

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用相对布局来定位每个项目相对于另一个项目。可能会有所帮助。在相对布局中包含所有布局并使用诸如to_right之类的方面等。总是适用于我