android - CardView底部边框在ScrollView android内部被切断

标签 android scrollview cardview

我把cardview放在scrollview里面,我们希望看到底部应该显示边框(见下图)。但它不是。问题是我不能滚动到底部看到cardview的边框。

关于 SO 的所有解决方案都是将 layout_margins 更改为 paddings,但如果我们想显示边框,cardview 的情况并非如此。我基本上什么都试过了。但还是不行。 scroll to bottom cannot see the border

图片1.滚动到底部看不到边框

we can see the top border

图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

I can't show LinearLayout at bottom to scroll view

Android ScrollView refuses to scroll to bottom

最佳答案

更新

现在使用 NestedScrollViewMaterialCardView 效果会更好。我将此 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 展开并向上滚动时,红色框显示已添加填充的位置。

screenshot

关于android - CardView底部边框在ScrollView android内部被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38572747/

相关文章:

android - 滚动时 ListView 元素背景颜色变为黑色

android - 如何摆脱 CardView 中 ImageView 周围的空白

android - 在运行时将布局动态插入到 Activity 中

android - Android VideoView 可以用作 PhoneGap 插件吗?

Iphone:ScrollView 强制到底部

java - Android 卡 View 通过拖放更改位置

android - 从 cardview 中删除额外的空间

Android studio 启动失败 :Fatal error initializing 'com. intellij.util.net.ssl.CertificateManager

android - 如何从 Arraylist 值创建 Json?

android - ScrollView 中的 ListView 在 Android 上不滚动