ScrollView无法在CardView中运行

时间:2017-10-25 07:40:56

标签: android android-cardview android-scrollview

我已经搜索过了,答案都没有帮助我。

这是我的布局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的限制,还是任何人都知道这是一个有效的解决方案。

3 个答案:

答案 0 :(得分:3)

如果您使用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 下。

答案 1 :(得分:0)

在ScrollView中设置此属性

android:fillViewport="true" 

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

答案 2 :(得分:0)

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

相关问题