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