Как создать скользящий CardView внутри DrawerLayout? - PullRequest
0 голосов
/ 30 мая 2019

Я работаю над созданием CardView с возможностью скольжения по горизонтали.

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

Итак, вот скриншот моего приложения.Два белых пробела - это CardView, над которым я работаю.

enter image description here

Моя цель - что-то похожее на раздвижные карты в Google Play Store:

enter image description here

А вот часть моего activity_main.xml:

<android.support.v4.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity"
    tools:openDrawer="start">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
<TextView
            android:id="@+id/jdCampusText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:text="JD Campus"
            android:textSize="26sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="@+id/jdCampusCard"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.332" />

        <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/jdCampusCard"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_gravity="center"
            android:layout_marginStart="8dp"
            android:layout_marginTop="0dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            card_view:cardCornerRadius="4dp"
            card_view:layout_constraintBottom_toBottomOf="parent"
            card_view:layout_constraintEnd_toEndOf="parent"
            card_view:layout_constraintStart_toStartOf="parent"
            card_view:layout_constraintTop_toTopOf="parent">
        </android.support.v7.widget.CardView>

        <TextView
            android:id="@+id/bsCampusText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:text="BS Campus"
            android:textSize="26sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="@+id/bsCampusCard"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.657" />

        <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/bsCampusCard"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_gravity="center"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            card_view:cardCornerRadius="4dp"
            card_view:layout_constraintBottom_toBottomOf="parent"
            card_view:layout_constraintEnd_toEndOf="parent"
            card_view:layout_constraintHorizontal_bias="0.0"
            card_view:layout_constraintStart_toStartOf="parent"
            card_view:layout_constraintTop_toTopOf="parent"
            card_view:layout_constraintVertical_bias="0.884">
        </android.support.v7.widget.CardView>

    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.DrawerLayout>

Это не обязательно должно быть CardViewчто-нибудь, что может быть скользящим и может быть onClick хорошо для меня.

...