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

Android布局问题:ScrollView中最后一项无法完全显示

解决ScrollView中最后一项被截断的问题

你的布局核心问题在于ScrollView的子布局高度设置错误,导致ScrollView无法正确计算内容的实际高度,超出屏幕的部分被截断。按以下步骤修改即可解决:

  • 调整ScrollView直接子布局高度:将ConstraintLayout的android:layout_height从match_parent改为wrap_content,让ScrollView能根据内容自动扩展可滚动范围。
  • 移除不必要的高度约束:内部根LinearLayout的android:layout_height也改成wrap_content,同时删掉layout_weight属性——weight是给固定高度容器内的布局分配比例用的,在ScrollView里完全不需要。
  • 保留底部间距:ConstraintLayout的android:paddingBottom="16dp"可以保留,确保最后一项和屏幕底部有足够的空白间隔。

修改后的完整布局代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fillViewport="true"
    tools:context=".PartnerInfosActivity">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="16dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginTop="-32dp"
                android:layout_weight="1"
                app:cardCornerRadius="32dp">

                <ImageView
                    android:id="@+id/partner_ppic_iv"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="32dp"
                    android:scaleType="centerCrop"
                    app:srcCompat="@drawable/partner" />

            </androidx.cardview.widget.CardView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/custom_radius"
                android:orientation="vertical"
                android:paddingStart="16dp"
                android:paddingEnd="16dp">

                <TextView
                    android:id="@+id/partner_name_tv_info"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/biennale_bold"
                    android:text="Partner Name"
                    android:textColor="@color/dark2"
                    android:textSize="32sp" />

                <TextView
                    android:id="@+id/partner_desc_tv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:fontFamily="@font/biennale_regular"
                    android:maxLines="5"
                    android:text="this is a brief descreption of the partner for example you can say that the partner is located at and has a lot functionalaties and you are going to like it if you want enjoy"
                    android:textColor="@color/dark4"
                    android:textSize="16sp" />

                <TextView
                    android:id="@+id/partner_phone_tv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="2dp"
                    android:drawablePadding="5dp"
                    android:fontFamily="@font/biennale_medium"
                    android:gravity="center_vertical"
                    android:text="0793802237"
                    android:textColor="@color/dark3"
                    android:textSize="16sp"
                    app:drawableStartCompat="@drawable/phone"
                    app:drawableTint="@color/dark5" />

                <TextView
                    android:id="@+id/partner_location_tv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="8dp"
                    android:drawablePadding="8dp"
                    android:fontFamily="@font/biennale_medium"
                    android:gravity="center_vertical"
                    android:text="Tlemcen, Hennaya"
                    android:textColor="@color/dark3"
                    android:textSize="16sp"
                    app:drawableStartCompat="@drawable/location"
                    app:drawableTint="@color/dark5" />

                <androidx.cardview.widget.CardView
                    android:id="@+id/browse_lost_items_cv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    app:cardCornerRadius="16dp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/blue_gradient" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="16dp">


                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:orientation="vertical">

                            <ImageView
                                android:layout_width="30dp"
                                android:layout_height="30dp"
                                android:src="@drawable/items_icon" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/biennale_bold"
                                android:text="Browse items"
                                android:textColor="@color/white"
                                android:textSize="20sp" />
                        </LinearLayout>

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_weight="1"
                            android:src="@drawable/two_arrows"
                            app:tint="@color/white" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>
                <androidx.cardview.widget.CardView
                    android:id="@+id/report_lost_item_cv"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    app:cardCornerRadius="16dp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/blue_gradient" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="16dp">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:orientation="vertical">

                            <ImageView
                                android:layout_width="30dp"
                                android:layout_height="30dp"
                                android:src="@drawable/report" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:fontFamily="@font/biennale_bold"
                                android:text="Report items"
                                android:textColor="@color/white"
                                android:textSize="20sp" />
                        </LinearLayout>

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_weight="1"
                            android:src="@drawable/two_arrows"
                            app:tint="@color/white" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>
                <androidx.cardview.widget.CardView
                    android:id="@+id/report_lost_item_cv2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    app:cardCornerRadius="16dp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/blue_gradient" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="16dp">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:orientation="vertical">

                            <ImageView
                                android:layout_width="30dp"
                                android:layout_height="30dp"
                                android:src="@drawable/report" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:fontFamily="@font/biennale_bold"
                                android:text="Report items"
                                android:textColor="@color/white"
                                android:textSize="20sp" />
                        </LinearLayout>

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_weight="1"
                            android:src="@drawable/two_arrows"
                            app:tint="@color/white" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>
                <androidx.cardview.widget.CardView
                    android:id="@+id/report_lost_item_cv3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    app:cardCornerRadius="16dp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@drawable/blue_gradient" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="16dp">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:orientation="vertical">

                            <ImageView
                                android:layout_width="30dp"
                                android:layout_height="30dp"
                                android:src="@drawable/report" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:fontFamily="@font/biennale_bold"
                                android:text="Report items"
                                android:textColor="@color/white"
                                android:textSize="20sp" />
                        </LinearLayout>

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_weight="1"
                            android:src="@drawable/two_arrows"
                            app:tint="@color/white" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>
            </LinearLayout>

        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

内容的提问来源于stack exchange,提问作者Aymen Mellah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 04:15:53