Search code examples
androidandroid-linearlayoutandroid-cardview

scrolling cardview is not working


I am new in android app development. I am making a project in android-studio. I want to list of cardview that will slide. If anyone knows the answer,please share your answer and xml code too.My xml code is below

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/images"
tools:context="litifer.awesome.game.cardview.MainActivity"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cardView1"
    android:layout_gravity="center"
    android:layout_marginTop="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    app:cardCornerRadius="5dp"
    app:cardElevation="5dp"
    android:clickable="true"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cardView1Text"
        android:text="Get in Touch"
        android:textSize="20dp"
        android:paddingTop="40dp"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cardView1Edit"
        android:hint="Enter Email here"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/cardView1Button"
        android:text="Submit"
        android:layout_gravity="center" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="40dp"/>
    </LinearLayout>
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:id="@+id/cardView2"
    android:layout_gravity="center"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    app:cardCornerRadius="5dp"
    app:cardElevation="5dp"
    android:clickable="true">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView2Text"
            android:text="Bluetooth demo"
            android:textSize="20dp"
            android:paddingTop="20dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView1Text1"
            android:text="Send Notification when in Bluetooth range"
            android:textSize="20dp"
            android:clickable="true"
            android:paddingBottom="40dp"/>
    </LinearLayout>
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:id="@+id/cardView3"
    android:layout_gravity="center"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    app:cardCornerRadius="5dp"
    app:cardElevation="5dp"
    android:clickable="true"
    android:paddingTop="40dp"
    android:paddingBottom="40dp">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView3Text"
            android:text="Wifi Demo"
            android:textSize="20dp"
            android:paddingTop="40dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView3Text1"
            android:text="Send Notification when in Wifi range"
            android:textSize="20dp"
            android:paddingBottom="40dp"/>
    </LinearLayout>
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cardView4"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    app:cardCornerRadius="5dp"
    app:cardElevation="5dp"
    android:layout_gravity="center"
    android:clickable="true"
    android:paddingTop="40dp"
    android:paddingBottom="40dp"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView4Text"
            android:text="Review Demo"
            android:textSize="20dp"
            android:paddingTop="40dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView4Text1"
            android:text="Get Customer Reviews using beacons"
            android:textSize="20dp"
            android:paddingBottom="40dp"/>
    </LinearLayout>

</android.support.v7.widget.CardView></LinearLayout>

Solution

  • Find the solution

    <ScrollView 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewReport="true">
    
    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/images"
    tools:context="litifer.awesome.game.cardview.MainActivity">
    //-----------
    //-----------
    
    </LinearLayout>
    
    </ScrollView>