Android 中 ScrollView滚动不到最底端的解决方法

在用ScrollView包裹TextView时发现。滚动条有时候滚动不到最底端,原因是在TextView中设置了Android:layout_marginTop="20dp",导致marginTop之后,scrollView初始显示的位置向下移动了20dp,你如果想要让他正常显示,必须在代码里面设置一下scrollView的初始显示位置就可以了。mScrollView.smoothScrollTo(0,0).

当然可以去掉TextView的marginTop,在它上面的组件设置layout_marginBottom也是OK的,这样ScrollView中的内容就可以完全显示了,代码如下

 <ImageView
            android:id="@+id/contentImage"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="3dp"
            android:layout_weight="3"
            android:layout_marginBottom="10dp"
            android:background="@android:color/transparent"
          />

        <ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:scrollbars="vertical" 
    android:fadeScrollbars="false"  
    android:layout_weight="7"> 
        <TextView
            android:id="@+id/newsContent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:text="@string/content"
            android:textColor="@android:color/black" 
      
        />
        </ScrollView>

相关阅读

ScrollView中嵌套ListView滚动效果冲突问题解决 http://www.linuxidc.com/Linux/2013-03/80240.htm

Android自定义ScrollView实现反弹效果【附源码】 http://www.linuxidc.com/Linux/2012-03/56007.htm

Android 下拉刷新控件之ScrollView版本实现 http://www.linuxidc.com/Linux/2012-02/53143.htm

Android基础教程:ScrollView和ListView套用冲突的解决方法 http://www.linuxidc.com/Linux/2011-11/47429.htm

Android开发:ScrollView/HorizontalScrollView常用技巧 http://www.linuxidc.com/Linux/2011-09/43135.htm

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值