ScrollView 使用fillViewport铺满全屏

本文介绍了如何使用ScrollView的fillViewport属性确保ScrollView及其子布局能够填充整个屏幕,即便子布局的高度不足以覆盖全屏。通过设置android:fillViewport=true,可以解决子布局无法铺满全屏的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当scrollview的子布局不足以铺满全屏的时候,scrollview的高度就是子布局高度之和,这个时候如果我们想让scrollview铺满全屏只需要设置 fillViewport=true就好了

 android:fillViewport="true"

举例:比如scrollview有一个子布局linerlayout,如果没有android:fillViewport=”true”,即使给linerlayout设置了 android:layout_height=”match_parent”也是没有作用的,它还是会按照wrap_coent来布局,最后无法铺满全屏。加上 android:fillViewport=”true”就可以让子布局的match_parent生效了。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:fillViewport="true"
    android:layout_height="match_parent">

    <LinearLayout 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"
        android:background="#f3f3f3"
        android:orientation="vertical"
        tools:context="www.yiba.com.dateme.chat.ui.TranslationActivity">
         <TextView
            android:id="@+id/tv_translate_tip"
            android:layout_width="match_parent"
            android:layout_height="36.0dp"
            android:layout_marginLeft="14.0dp"
            android:gravity="center_vertical"
            android:text="Translation"
            android:textColor="#FFC4C9D0"
            android:textSize="15.0sp"
            android:visibility="gone" />
    </LinearLayout>

</ScrollView>

scrollview

如图,在scrollview里让布局显示在屏幕底部。需要给scrollview加上 android:fillViewport=”true”属性

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值