[英]ScrollView not working inside CardView
I have already searched SO and none of the answer helped me. 我已经搜索过了,没有一个答案对我有帮助。
Here is my layout xml: 这是我的布局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>
I'm adding child views to my LinearLayout
dynamically via code. 我通过代码动态地将子视图添加到我的
LinearLayout
。 I have also tried to move the ScrollView
tag to wrap CardView
but still no luck. 我也尝试移动
ScrollView
标签来包装CardView
但仍然没有运气。 Is this a limitation of CardView
or do any one know a working solution to this. 这是
CardView
的限制还是任何人都知道这是一个有效的解决方案。
It will be better if you use NestedScrollView
. 如果使用
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.
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 FYI
You can put your CardView
under ScrollView
. 您可以将您的
CardView
放在ScrollView
下。
set this property in ScrollView 在ScrollView中设置此属性
android:fillViewport="true"
and set height of cardview to match parent or fixed 并设置cardview的高度以匹配父级或固定
Okay first of all thanks to every one for helping with your valauble suggestions. 好的,首先感谢每一个人帮助你提出的valauble建议。 The actual problems lies with the
ConstraintLayout
. 实际问题在于
ConstraintLayout
。 All needs to be done is add a constraint app:layout_constraintBottom_toBottomOf="parent"
to the cardview and set android:layout_height="0dp"
. 所有需要做的就是在cardview中添加一个约束
app:layout_constraintBottom_toBottomOf="parent"
并设置android:layout_height="0dp"
。 The cardview didn't have any boundary inforced. cardview没有任何强制边界。 Unlike LinearLayout and RelativeLayout which by default inforce the boundary to their child views.
与LinearLayout和RelativeLayout不同,LinearLayout和RelativeLayout默认强制实施其子视图的边界。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.