微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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下.

原文地址:https://www.jb51.cc/android/1075108.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐