You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android ScrollView中第三个MaterialCardView边框缺失问题

问题原因

第三个MaterialCardView边框(尤其底部)偶发缺失由两个布局配置问题共同导致:

  • 作为ScrollView直接子容器的内层ConstraintLayout,未正确配置最后一个子项的底部约束。ScrollView计算可滚动内容总高度时,若最后一个子View未绑定父容器底部约束,会出现高度计算偏差,将卡片底部的边框、阴影区域排除在可绘制区域外。
  • 父容器默认开启边界裁剪,MaterialCardView的elevation阴影、圆角边框存在部分绘制区域超出自身布局边界,会被父容器裁剪逻辑截断,最终出现边框显示不全的问题。
修复方案
  • 给第三个卡片cv_item_description新增约束app:layout_constraintBottom_toBottomOf="parent",同时添加android:layout_marginBottom="10dp"的底部外边距。
  • 将内层ConstraintLayout原全局属性android:padding="10dp"修改为android:paddingStart="10dp" android:paddingEnd="10dp" android:paddingTop="10dp",移除全局底部内边距,避免和最后一个卡片的外边距叠加引发高度计算错误。
  • 给ScrollView和内层ConstraintLayout均添加android:clipToPadding="false"、android:clipChildren="false"属性,关闭父容器对子View绘制区域的裁剪,保证卡片阴影、边框完整渲染。
修正后完整布局代码
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:clipToPadding="false"
    android:clipChildren="false"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        android:paddingTop="10dp"
        android:clipToPadding="false"
        android:clipChildren="false">

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/cv_item_info"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:backgroundTint="@color/white"
            app:cardCornerRadius="20dp"
            app:cardElevation="2dp"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="10dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:layout_marginBottom="15dp"
                android:layout_marginStart="20dp"
                android:layout_marginEnd="20dp"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/tv_item_nama"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/nama_item"
                    android:textColorHint="@color/black"
                    android:fontFamily="@font/poppins_medium"
                    android:text=""
                    android:textStyle="bold"
                    android:textSize="14sp"
                    android:textColor="@color/black"
                    android:maxLines="1"
                    android:ellipsize="end"/>

                <TextView
                    android:id="@+id/tv_item_category"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:hint="@string/category_item"
                    android:text=""
                    android:fontFamily="@font/poppins"
                    android:textSize="11sp"
                    android:maxLines="1"
                    android:ellipsize="end"/>

                <TextView
                    android:id="@+id/tv_item_harga"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:hint="@string/harga_item"
                    android:textColorHint="@color/black"
                    android:text=""
                    android:fontFamily="@font/poppins"
                    android:textSize="14sp"
                    android:textColor="@color/black"
                    android:maxLines="1"
                    android:ellipsize="end" />

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

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/cv_seller_profile"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:backgroundTint="@color/white"
            app:cardCornerRadius="20dp"
            app:cardElevation="2dp"
            android:layout_marginTop="20dp"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="10dp"
            app:layout_constraintTop_toBottomOf="@id/cv_item_info"
            app:layout_constraintStart_toStartOf="parent">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="15dp"
                android:layout_marginBottom="15dp"
                android:layout_marginStart="20dp"
                android:layout_marginEnd="20dp">

                <androidx.cardview.widget.CardView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center"
                    app:cardCornerRadius="20dp">

                    <ImageView
                        android:id="@+id/iv_seller_info"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:src="@mipmap/ic_launcher"
                        android:contentDescription="@string/seller_picture" />

                </androidx.cardview.widget.CardView>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <TextView
                        android:id="@+id/tv_seller_nama"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="10dp"
                        android:layout_marginTop="10dp"
                        android:fontFamily="@font/poppins_medium"
                        android:textStyle="bold"
                        android:textColor="@color/black"
                        android:text=""
                        android:textSize="14sp"
                        android:hint="@string/seller_name"
                        android:textColorHint="@color/black"/>

                    <TextView
                        android:id="@+id/tv_seller_city"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="10dp"
                        android:layout_marginTop="10dp"
                        android:textSize="11sp"
                        android:text=""
                        android:fontFamily="@font/poppins"
                        android:hint="@string/seller_city"/>
                </LinearLayout>
            </LinearLayout>
        </com.google.android.material.card.MaterialCardView>

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/cv_item_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/white"
            app:cardCornerRadius="20dp"
            app:cardElevation="2dp"
            android:layout_marginTop="20dp"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginBottom="10dp"
            app:layout_constraintTop_toBottomOf="@id/cv_seller_profile"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="20dp">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/deskripsi"
                    android:fontFamily="@font/poppins_medium"
                    android:textColorHint="@color/black"
                    android:textStyle="bold"
                    android:textSize="14sp"
                    android:textColor="@color/black"
                    android:text=""/>

                <TextView
                    android:id="@+id/tv_deskripsi"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="Test"
                    android:fontFamily="@font/poppins"
                    android:textSize="14sp"
                    android:textColor="@color/black" />
            </LinearLayout>
        </com.google.android.material.card.MaterialCardView>
    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

内容的提问来源于stack exchange,提问作者Zen Ryuu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 15:24:34