繁体   English   中英

ScrollView无法在CardView中运行

[英]ScrollView not working inside 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就像ScrollView一样,但它支持在新旧版本的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下。

在ScrollView中设置此属性

android:fillViewport="true" 

并设置cardview的高度以匹配父级或固定

好的,首先感谢每一个人帮助你提出的valauble建议。 实际问题在于ConstraintLayout 所有需要做的就是在cardview中添加一个约束app:layout_constraintBottom_toBottomOf="parent"并设置android:layout_height="0dp" cardview没有任何强制边界。 与LinearLayout和RelativeLayout不同,LinearLayout和RelativeLayout默认强制实施其子视图的边界。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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