android – ScrollView无法在CardView中运行

我已经搜索过了,没有一个答案对我有帮助.

这是我的布局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>

我通过代码动态地将子视图添加到我的LinearLayout.我也尝试移动ScrollView标签来包装CardView,但仍然没有运气.这是CardView的限制还是任何人都知道这是一个有效的解决方案.

解决方法:

如果你使用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

您可以将您的CardView放在ScrollView下.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...