johnson
johnson

Reputation: 131

How do i achieve this sort of swipe navigation

I have a grid layout containing multiple linear layouts. Each linear layout contains an image view and a text view. Currently all the images and their description appear on the screen but i want to create a swipe functionality which will make another set of images appear when the user swipe the screen. I want to create something just like this

what i want to achieve

Here is my xml file

  <GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnCount="4">

        <LinearLayout
            android:onClick="facility_click"
            android:id="@+id/layout_facility1"
            android:layout_columnWeight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image1"
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/fridge1"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Fridge"
                android:textAlignment="center"/>

        </LinearLayout>

        <LinearLayout
            android:onClick="facility_click"
            android:id="@+id/layout_facility2"
            android:layout_columnWeight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image2"
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/alarmclock" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Alarm clock"
                android:textAlignment="center"/>

        </LinearLayout>

        <LinearLayout
            android:onClick="facility_click"
            android:id="@+id/layout_facility3"
            android:layout_columnWeight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image3"
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/dishwasher1" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Dish washer"
                android:textAlignment="center"/>

        </LinearLayout>


        <LinearLayout
            android:onClick="facility_click"
            android:id="@+id/layout_facility4"
            android:layout_columnWeight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image4"
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/fridge1" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Fridge"
                android:textAlignment="center"/>

        </LinearLayout>


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

            <ImageView
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/fridge1"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Fridge"
                android:textAlignment="center"/>

        </LinearLayout>

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

            <ImageView
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/alarmclock" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Alarm clock"
                android:textAlignment="center"/>

        </LinearLayout>

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

            <ImageView
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/dishwasher1" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Dish washer"
                android:textAlignment="center"/>

        </LinearLayout>


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

            <ImageView
                android:layout_width="50dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:src="@drawable/fridge1" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Fridge"
                android:textAlignment="center"/>

        </LinearLayout>

    </GridLayout>

Upvotes: 0

Views: 64

Answers (2)

jp singh
jp singh

Reputation: 344

I would suggest you to use a RecycleView adapter and a cardView along with it....it is quite easy as compared to all the other methods. Just don't forget to add both RecycleView and cardView dependencies in you build.gradle

Upvotes: 1

muminers
muminers

Reputation: 1210

I'd guess that you need ViewPager:

https://developer.android.com/training/animation/screen-slide.html

Each "grid" will be separate fragment.

EDIT:

Also see this: it seems very simmilar to what you want to get: Android ViewPager with bottom dots

Upvotes: 1

Related Questions