0

I'm working on creating CardView that are slidable horizontally.

I've been searching on Internet and watching tutorials on YouTube for days. After trying those possible solutions and advice, my app either gets errors I couldn't solve or crashes.

So, here's a screenshot of my app. The two white blank spaces are the CardView I'm working on.

enter image description here

My goal is something similar to the sliding cards in Google Play Store:

enter image description here

And here's part of my 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>

It doesn't need to be CardView, anything that's slidable, and can be onClick is fine for me.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Jerry Chen
  • 11,595
  • 5
  • 13
  • 16
  • You just need to know that the `RecyclerView` can be [horizontal too](https://stackoverflow.com/questions/28460300/how-to-build-a-horizontal-listview-with-recyclerview). – coroutineDispatcher May 30 '19 at 09:40
  • Possible duplicate of https://stackoverflow.com/questions/44211617/horizontal-recycler-view-with-horizontal-scroll – Ankit Tale May 30 '19 at 10:16
  • Possible duplicate of [horizontal recycler view with horizontal scroll](https://stackoverflow.com/questions/44211617/horizontal-recycler-view-with-horizontal-scroll) – Ankit Tale May 30 '19 at 10:16

0 Answers0