在ScrollView android内部切断了CardView底部边框

Che*_*eng 16 android scrollview cardview

我将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>
Run Code Online (Sandbox Code Playgroud)

参考: ScrollView不会滚动到底部

ScrollView会切掉顶部并在底部留出空间

我无法在底部显示LinearLayout以滚动视图

Android ScrollView拒绝滚动到底部

Ray*_*ter 18

我遇到了同样的问题并且必须执行以下操作(关键是我在添加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">
Run Code Online (Sandbox Code Playgroud)

在cardview周围添加LinearLayout包装器对我有用.

另请注意,我必须在cardview上添加card_view:cardUseCompatPadding ="true"以使边框阴影看起来正确.

这是最终结果,其中红色框显示了当扩展和向上滚动cardview时添加填充的位置.

截图

  • 我无法完成这项工作,唯一有效的是在"CardView"中添加`app:cardUseCompatPadding ="true"`,如本答案所述.谢谢! (3认同)

And*_*ndy 7

Setting clipToPadding to false on a ScrollView usually works for me:

    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:paddingBottom="16dp">

    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:contentPadding="8dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:text="Lorem ipsum..." />

    </com.google.android.material.card.MaterialCardView>

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

  • 只是将 `clipToPadding` 添加到 `false` 到 MaterialCardView 的父级对我有用 (4认同)

Che*_*eng 5

我刚刚发现的一种解决方案是用LinearLayout或RelativeLayout包装CardView并设置其填充。例如,如果要在cardView中使用一些阴影效果,比如说8dp,则可以设置LinearLayout或RelativeLayout的4dp填充以及CardView的4dp layout_margin。