设置listview高度包裹内容

设置listview高度包裹内容,可以在布局文件设置height为wrap_content

public class ExpandListView extends ListView{
    public ExpandListView(Context context,AttributeSet attrs){
        super(context,attrs);
    }
    private int maxHeight = 0;
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        int expandSepc = 0;
        if(maxHeight > 0){
            expandSepc = maxHeight;
        }else{
            expandSepc = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec,expandSepc);
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当显示的内容超过屏幕高度时,你可以考虑使用 `ListView` 的 `physics` 属性来添加滚动功能,以便用户可以滚动查看超出屏幕高度内容。 在你的代码中,将 `ListView.builder` 包裹在一个具有固定高度的容器中,并将 `physics` 属性设置为 `AlwaysScrollableScrollPhysics()`,这样用户就可以滚动查看内容。 以下是修改后的代码示例: ```dart Column( children: [ Expanded( child: Container( color: Colors.white, padding: EdgeInsets.fromLTRB(20, 20, 10, 10), child: Column( children: [ nameDetailView("事件", title, ShiJianTime, title, []), SizedBox(height: 20), Divider(color: Colors.blue, height: 1.0, thickness: 1.0), SizedBox(height: 20), chuliDetail(), Container( height: MediaQuery.of(context).size.height * 0.6, // 设置一个固定高度,根据需要进行调整 child: ListView.builder( physics: AlwaysScrollableScrollPhysics(), // 允许滚动 itemCount: LogList.length, itemBuilder: (BuildContext context, int index) { return _getItemView(index); }, ), ), ], ), ), ), ], ), ``` 在这个示例中,我将 `Container` 的高度设置为屏幕高度的 60%,你可以根据需要进行调整。通过将 `physics` 属性设置为 `AlwaysScrollableScrollPhysics()`,即使内容超过屏幕高度,用户也可以滚动查看。 如果你的内容超出屏幕高度时仍然无法滚动,请确保 `ListView` 的父容器也具有足够的高度以容纳 `ListView`。 希望这可以解决你的问题。如果问题仍然存在,请提供更多相关代码或错误信息,以便我更好地帮助你解决问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值