简体   繁体   中英

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.

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 .

set this property in ScrollView

android:fillViewport="true" 

and set height of cardview to match parent or fixed

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM