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

Android应用ScrollView不显示问题,子LinearLayout已设wrap_content

问题排查与修复方案

核心问题点

  • 你当前贴出的代码中ScrollView的android:layout_height仍为wrap_content,这会导致ScrollView高度随子布局高度自适应,没有固定滚动视口,自然无法触发滚动效果,必须修改为match_parent。
  • ScrollView上设置了无效属性android:orientation="vertical"和会干扰布局的android:gravity="center":前者是LinearLayout专属属性,在ScrollView上添加无意义;后者会导致子布局在内容超过屏幕高度时被上下裁剪,需直接删除这两个属性。
  • 退出按钮的android:layout_alignParentBottom="true"是RelativeLayout的布局参数,父布局为LinearLayout时该属性无效,可直接删除。

修改后完整代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
        android:id="@+id/Scroll"
        android:fillViewport="true"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    <LinearLayout
            android:id="@+id/LL2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center">

        <TextView
                android:id="@+id/TV1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Test"
                android:clickable="false" 
                android:textSize="20sp"/>
        <TextView
                android:id="@+id/link"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Loading..."
        />

        <TextView
                android:id="@+id/TV2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Test"
                android:textSize="20sp"/>

        <TextView
                android:id="@+id/TV3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Test"
                android:textSize="20sp"/>

        <TextView
                android:id="@+id/TV4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Earnings:"
                android:textSize="20sp"/>

        <TextView
                android:id="@+id/User_earnings"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Loading..."
                android:textSize="20sp"/>

        <TextView
                android:id="@+id/TV6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Test"
                android:textSize="20sp"/>

        <Button
                android:id="@+id/btnLogOut"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="15dp"
                android:text="Logout"/>
    </LinearLayout>
</ScrollView>

额外说明

如果修改后横屏仍有适配问题,可检查Activity配置是否锁定了布局方向,或子View是否有固定高度设置导致内容溢出。

内容的提问来源于stack exchange,提问作者Ken Adams

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 16:54:03