eC Droid
eC Droid

Reputation: 681

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.

Upvotes: 7

Views: 7252

Answers (3)

eC Droid
eC Droid

Reputation: 681

Okay first of all thanks to every one for helping with your valauble suggestions. The actual problems lies with the ConstraintLayout. All needs to be done is add a constraint app:layout_constraintBottom_toBottomOf="parent" to the cardview and set android:layout_height="0dp". The cardview didn't have any boundary inforced. Unlike LinearLayout and RelativeLayout which by default inforce the boundary to their child views.

Upvotes: 2

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

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.

Upvotes: 4

Munir
Munir

Reputation: 2558

set this property in ScrollView

android:fillViewport="true" 

and set height of cardview to match parent or fixed

Upvotes: 1

Related Questions