为了账号安全,请及时绑定邮箱和手机立即绑定

Flowlayout和Scrollview共存的问题

如题~加入项目后,在flowlayout外面套一层ScrollLayout就会显示不出来~求解答。。。

正在回答

3 回答

你好,我在视频中的布局文件外层添加了ScrollView,一切正常呀~

测试布局文件如下:

<ScrollView 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">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <com.imooc.view.FlowLayout
            android:id="@+id/id_flowlayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#E5E5F5"
            android:padding="20dp" >
        </com.imooc.view.FlowLayout>
    </RelativeLayout>

</ScrollView>


0 回复 有任何疑惑可以回复我~
#1

weirdguy

我最近遇到一个问题,使用ScrollView嵌套ListView ListviewView里的item包含FlowLayout的布局 因为需要计算Listview中item的高度 但是在计算测量的时候 因为FlowLayout要多次测量才能得到准确的值 所有每次计算时都出现计算的高度超过实际高度 导致ScrollView布局底部多出一大部分的空白 希望老师能指点下怎么解决?
2016-03-17 回复 有任何疑惑可以回复我~
#2

慕粉18604581180

请问解决了吗,我的是ListView 的View中包含FlowLayout,数据出现混乱 ,求解啊
2016-10-14 回复 有任何疑惑可以回复我~
//你可能这样写:
setMeasuredDimension(
    modeWidth == MeasureSpec.AT_MOST ? width + getPaddingLeft() + getPaddingRight() : sizeWidth,
    modeHeight == MeasureSpec.AT_MOST ? height + getPaddingTop()+ getPaddingBottom() : sizeHeight
);
//用ScrollView的话modeHeight和sizeHeight取值永远为0,0即不属于AT_MOST也不属于EXACTLY,而是属于UNSPECIFIED
//所以第二个三目表达式最终选择右边的sizeHeight,而sizeHeight=0,把高度设置为0,肯定显示不出来

//正确的写法:
setMeasuredDimension(
    modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width + getPaddingLeft() + getPaddingRight(),
    modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height + getPaddingTop()+ getPaddingBottom()
);
//因为modeHeight也不是EXACTLY,所以第二个三目表达式最终选择右边的height + getPaddingTop()+ getPaddingBottom(),这个是流式布局算好的值,所以可以显示


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
打造Android中的流式布局和热门标签
  • 参与学习       30489    人
  • 解答问题       56    个

酷炫的热门标签到底是怎么实现的呢,本教程会给你答案

进入课程

Flowlayout和Scrollview共存的问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信