加入收藏 | 设为首页 | 会员中心 | 我要投稿 常州站长网 (https://www.0519zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Android 中 ScrollView滚动不到最底端的解决措施

发布时间:2021-11-20 18:53:27 所属栏目:教程 来源:互联网
导读:在用ScrollView包裹TextView时发现。滚动条有时候滚动不到最底端,原因是在TextView中设置了Android:layout_marginTop=20dp,导致marginTop之后,scrollView初始显示的位置向下移动了20dp,你如果想要让他正常显示,必须在代码里面设置一下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>

(编辑:常州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读