我把cardview放在scrollview里面,我们希望看到底部应该显示边框(见下图)。但它不是。问题是我不能滚动到底部看到cardview的边框。
关于 SO 的所有解决方案都是将 layout_margins 更改为 paddings,但如果我们想显示边框,cardview 的情况并非如此。我基本上什么都试过了。但还是不行。
图片1.滚动到底部看不到边框
图2.我们可以看到上边框
下面是xml代码
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
...
</LinearLayout>
</CardView>
</LinearLayout>
引用: ScrollView doesn't scroll to the bottom
ScrollView cuts off the top and leaves space at the bottom
最佳答案
更新
现在使用 NestedScrollView
和 MaterialCardView
效果会更好。我将此 NestedScrollView
添加到 ConstraintLayout
。
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">
如果没有 LinearLayout 包装器,这对我有用。
================================================ ==============================
这里是老路
我遇到了同样的问题,必须执行以下操作(关键是我添加 paddingBottom 的 cardview 周围的 LinearLayout 包装器):
<ScrollView
android:id="@+id/item_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
tools:visibility="visible">
<LinearLayout
android:id="@+id/item_wrapper_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_margin"
android:paddingBottom="32dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/item_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/colorPrimary"
card_view:cardCornerRadius="4dp"
card_view:cardUseCompatPadding="true">
在卡片 View 周围添加 LinearLayout 包装器对我有用。
另外请注意,我必须在卡片 View 上添加 card_view:cardUseCompatPadding="true" 才能使边框阴影看起来正确。
这是最终结果,当卡片 View 展开并向上滚动时,红色框显示已添加填充的位置。
关于android - CardView底部边框在ScrollView android内部被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38572747/