水平滚动视图以显示名片视图

This is my xml file where I am showing today's, tomorrow's and day after's weather details in 3 different card views. Here's a screenshot of my design enter image description here

这是xml代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".dashboard">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/hello"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="30dp"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="25dp"
            android:textColor="#089471"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />


        <androidx.cardview.widget.CardView
            android:id="@+id/cd1"
            app:cardCornerRadius="10dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="20dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/hello"
            app:layout_constraintVertical_bias="0.0"
            android:layout_width="match_parent">


            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="155dp">

                <ProgressBar
                    android:id="@+id/pb"
                    android:visibility="gone"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    android:indeterminateTint="#4D000000"/>

                <TextView
                    android:id="@+id/txt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Loading. Please wait ..."
                    android:textSize="12sp"
                    android:visibility="gone"
                    app:layout_constraintEnd_toEndOf="@id/pb"
                    app:layout_constraintStart_toStartOf="@id/pb"
                    app:layout_constraintTop_toBottomOf="@id/pb" />


                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="10dp"
                    android:text="Today"
                    android:textSize="20sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/dnt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:layout_marginTop="6dp"
                    android:layout_marginEnd="15dp"
                    android:layout_marginRight="15dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/loc1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:layout_marginTop="2dp"
                    app:layout_constraintEnd_toEndOf="@+id/dnt"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/dnt" />

                <com.airbnb.lottie.LottieAnimationView
                    android:id="@+id/lAV1"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_marginStart="12dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="8dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView7"
                    app:layout_constraintVertical_bias="0.0"
                    app:lottie_autoPlay="true"
                    app:lottie_colorFilter="#089471"
                    app:lottie_loop="true"/>

                <TextView
                    android:id="@+id/Temp_today"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="8dp"
                    android:textColor="#089471"
                    android:textSize="20sp"
                    android:textStyle="bold"
                    app:layout_constraintBottom_toBottomOf="@+id/lAV1"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toEndOf="@+id/lAV1"
                    app:layout_constraintTop_toTopOf="@+id/lAV1"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/Min_Max"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/Temp_today"
                    app:layout_constraintTop_toBottomOf="@+id/Temp_today"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/humidity_today"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/rainp_today"
                    app:layout_constraintTop_toTopOf="@id/Temp_today"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/rainp_today"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:layout_marginEnd="10dp"
                    android:layout_marginRight="10dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/humidity_today"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/pressure_today"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/rainp_today"
                    app:layout_constraintTop_toBottomOf="@id/rainp_today"
                    app:layout_constraintVertical_bias="0.0" />

                <EditText
                    android:id="@+id/description_today"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="2dp"
                    android:background="@color/transparent"
                    android:clickable="false"
                    android:focusable="false"
                    android:inputType="textMultiLine"
                    android:minLines="2"
                    android:textColor="#089471"
                    android:textSize="14sp"
                    android:gravity="top"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="@id/rainp_today"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/Temp_today"
                    app:layout_constraintTop_toBottomOf="@id/Min_Max"
                    app:layout_constraintVertical_bias="0.0"
                    android:layout_marginEnd="2dp" />


            </androidx.constraintlayout.widget.ConstraintLayout>

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/cd2"
            app:cardCornerRadius="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cd1"
            app:layout_constraintVertical_bias="0.0">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="155dp">

                <TextView
                    android:id="@+id/textView77"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="10dp"
                    android:text="Tomorrow"
                    android:textSize="20sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/tommorowdate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:layout_marginTop="6dp"
                    android:layout_marginEnd="15dp"
                    android:layout_marginRight="15dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/loc2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:layout_marginTop="2dp"
                    app:layout_constraintEnd_toEndOf="@+id/tommorowdate"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/tommorowdate" />

                <com.airbnb.lottie.LottieAnimationView
                    android:id="@+id/lAV2"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_marginStart="12dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="8dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView77"
                    app:layout_constraintVertical_bias="0.0"
                    app:lottie_autoPlay="true"
                    app:lottie_colorFilter="#089471"
                    app:lottie_loop="true" />

                <TextView
                    android:id="@+id/Min_Maxtom"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="8dp"
                    android:textColor="#089471"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    app:layout_constraintBottom_toBottomOf="@+id/lAV2"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toEndOf="@+id/lAV2"
                    app:layout_constraintTop_toTopOf="@+id/lAV2"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/humidity_tom"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/rainp_tom"
                    app:layout_constraintTop_toTopOf="@id/Min_Maxtom"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/rainp_tom"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:layout_marginEnd="10dp"
                    android:layout_marginRight="10dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/humidity_tom"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/pressure_tom"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/rainp_tom"
                    app:layout_constraintTop_toBottomOf="@id/rainp_tom"
                    app:layout_constraintVertical_bias="0.0" />

                <EditText
                    android:id="@+id/description_tom"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:background="@color/transparent"
                    android:clickable="false"
                    android:focusable="false"
                    android:inputType="textMultiLine"
                    android:minLines="2"
                    android:textColor="#089471"
                    android:textSize="14sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="@id/Min_Maxtom"
                    app:layout_constraintTop_toTopOf="@id/rainp_tom"
                    app:layout_constraintEnd_toStartOf="@id/humidity_tom"
                    app:layout_constraintVertical_bias="0.0"/>


            </androidx.constraintlayout.widget.ConstraintLayout>

        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:id="@+id/cd3"
            app:cardCornerRadius="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="20dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cd2"
            app:layout_constraintVertical_bias="0.0">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="155dp">

                <TextView
                    android:id="@+id/textView777"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="10dp"
                    android:text="Day After"
                    android:textSize="20sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/dadate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:layout_marginTop="6dp"
                    android:layout_marginEnd="15dp"
                    android:layout_marginRight="15dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/loc3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:layout_marginTop="2dp"
                    app:layout_constraintEnd_toEndOf="@+id/dadate"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/dadate" />

                <com.airbnb.lottie.LottieAnimationView
                    android:id="@+id/lAV3"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_marginStart="12dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="8dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView777"
                    app:layout_constraintVertical_bias="0.0"
                    app:lottie_autoPlay="true"
                    app:lottie_colorFilter="#089471"
                    app:lottie_loop="true"/>

                <TextView
                    android:id="@+id/Min_Maxda"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="8dp"
                    android:textColor="#089471"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    app:layout_constraintBottom_toBottomOf="@+id/lAV3"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toEndOf="@+id/lAV3"
                    app:layout_constraintTop_toTopOf="@+id/lAV3"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/humidity_da"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/rainp_da"
                    app:layout_constraintTop_toTopOf="@id/Min_Maxda"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/rainp_da"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:layout_marginEnd="10dp"
                    android:layout_marginRight="10dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/humidity_da"
                    app:layout_constraintVertical_bias="0.0" />

                <TextView
                    android:id="@+id/pressure_da"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="@id/rainp_da"
                    app:layout_constraintTop_toBottomOf="@id/rainp_da"
                    app:layout_constraintVertical_bias="0.0" />

                <EditText
                    android:id="@+id/description_da"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:background="@color/transparent"
                    android:clickable="false"
                    android:focusable="false"
                    android:inputType="textMultiLine"
                    android:minLines="2"
                    android:textColor="#089471"
                    android:textSize="14sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="@id/Min_Maxda"
                    app:layout_constraintTop_toTopOf="@id/rainp_da"
                    app:layout_constraintEnd_toStartOf="@id/humidity_da"
                    app:layout_constraintVertical_bias="0.0"/>



            </androidx.constraintlayout.widget.ConstraintLayout>

        </androidx.cardview.widget.CardView>



    </androidx.constraintlayout.widget.ConstraintLayout>


</FrameLayout>

我想在水平滚动视图中显示这三个cardview,但是约束完全被打乱了,并且没有正确显示。有人可以建议我在这里为这些卡添加水平滚动视图的正确方法是什么?任何帮助,将不胜感激。提前致谢。

评论