Linearlayout scrollbars=“vertical”并没有用,Linearlayout滚动的解决办法

当LinearLayout的内容超出屏幕时,直接设置scrollbars属性可能无效。正确解决方案是在LinearLayout外包裹一个ScrollView,确保滚动功能正常工作。博客详细介绍了如何通过在布局XML中正确使用ScrollView来避免内容溢出。

Linearlayout 的内容经常会超出屏幕,虽然有scrollbars="vertical"参数可以设置,然而并没有用。

正确的做法是在LinearLayout外嵌套一层ScrollView。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadingEdge="vertical"
    android:scrollbars="vertical">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="请选择日期:"
            android:textColor="@android:color/holo_blue_dark"
            android:textSize="22sp" />
<? xml version = "1.0"encoding = " utf-8" ? > android : layout_width = " match_parent" <LinearLayout xmlns: android = " http://schemas.android.com/apk/res/android" android :layout_height = " match_parent" android: orientation = " vertical" ><HorizontalScrollView android: layout_width = " wrap_content" android:layout_height = " 0dp" android:layout_weight ="1" android:scrollbars = " none" >< LinearLayout android:layout_width = " wrap_content" android:layout_height = " match_parent" android :orientation = " horizontal" ><View android: layout_width = "300dp" android :layout_height = " match_parent" android:background = "@color/red"/ ><View android:layout_width = "300dp" android ;layout_height = " match_parent" android:background = " @color/green"/ ><View android :layout_width ="300dp" android :layout_height = " match_parent" android:background = " @color/blue"/></LinearLayout ></HorizontalScrollView ><ScrollView android :layout_width = " match_parent"android :layout_height ="0dp" android :layout_weight ="1" android : scrollbars = " none" ><LinearLayout android :layout_width = " match_parent" android :layout_height = " wrap_content" android :orientation =" vertical" ><View android :layout_width = " match_parent" android :layout_height ="200dp" android:background =" @color/yellow"/ ><View android:layout_width = " match_parent" android :layout_height ="200dp" android;background =" @color/cyan"/ ><View android :layout_width = " match_parent" android:layout_height ="200dp" android :background = " @color/blue"/> </LinearLayout ></ScrollView>/LinearLayout >修正补全
09-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值