【安卓学习之常见问题】 ScrollView与其他组件的冲突问题

在app界面设计中,常常遇到 一个控件不能全部显示 想要显示的内容,就不需要用到滚动条ScrollView这个控件,而想要使得界面设计符合你的设计界面,却常常又遇到一个问题,当在ScrollView中内嵌 WebView、ListView等 自带 滚动效果的控件时,就会出现冲突。比如最为常见的 ScrollView内嵌ListView问题,百度下,可以看到很多相关内容,如下:
这里写图片描述

在这里 我恰好遇到的问题是:
使用开源控件:PullToRefreshScrollView来内嵌ListView,界面布局如下:

<com.handmark.pulltorefresh.library.PullToRefreshScrollView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pull_refresh_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        ptr:ptrAnimationStyle="flip" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="30dp"
                android:layout_marginBottom="3dip"
                android:background="#dcdcdc"
                android:gravity="center_vertical"
                android:paddingLeft="15dp"
                android:layout_marginTop="5dip"
                android:text="@string/list_title" />

            <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:dividerHeight="1dp" />
        </LinearLayout>
    </com.handmark.pulltorefresh.library.PullToRefreshScrollView>

本来要实现的是想要实现的效果图:
这里写图片描述
TextView 置顶,ListView根据手机屏幕填充剩余的空间,ListView如果列表太长,就会自动带有滚动功能。

结果效果是ListView只显示单行,带有滚动功能,和想要的效果天差地别

问题分析:

解决方法:

解决方法一:设置ListView为固定高度,不过要提前计算好他的高度,比较麻烦
解决方法二:在PullToRefreshScrollView属性中添加android:fillViewport=”true”

总结:
ScrollView中的组件设置android:layout_height=”fill_parent”不起作用的解决办法
在ScrollView中添加一个android:fillViewport=”true”属性就可以了。顾名思义,这个属性允许 ScrollView中的组件去充满它。

转载请注明出处:http://blog.csdn.net/ljb568838953/article/details/52563452

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值