Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView not working inside CardView

I have already searched SO and none of the answer helped me.

Here is my layout xml:

<android.support.v7.widget.CardView
        android:id="@+id/layout_building"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/_8dp"
        app:layout_constraintEnd_toStartOf="@+id/scrollview_nested_fragment_container"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/views_container">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/layout_building_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"/>

        </ScrollView>

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

I'm adding child views to my LinearLayout dynamically via code. I have also tried to move the ScrollView tag to wrap CardView but still no luck. Is this a limitation of CardView or do any one know a working solution to this.

like image 826
eC Droid Avatar asked Oct 25 '17 07:10

eC Droid


People also ask

What is ScrollView explain with example?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.


1 Answers

It will be better if you use NestedScrollView .

NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android.

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        //Your CHILD Layout

</android.support.v4.widget.NestedScrollView>

FYI

You can put your CardView under ScrollView.

like image 171
IntelliJ Amiya Avatar answered Oct 18 '22 01:10

IntelliJ Amiya