如果:

ScrollView.scrollTo(0,0);

ScrollView.fullScroll(View.FOCUS_UP) ;

ScrollView.smoothScrollTo(0, 0);

这三种方法都解决不了你的问题,那么请往下看;

布局有点复杂:

最外层是SwipeRefreshLayout嵌套ScrollView再嵌套LinearLayout再嵌套RecyclerView的;因为布局比较复杂,布局的位置还要求用户自己可以调整,使用的是LinearLayout动态添加View的方式,ScrollView让其可以滚动,SwioeRefreshLayout可以让界面下拉刷新;

但是功能都完成时发现ScrollView默认不在顶部;

1、设置了ScrollView.smoothScrollTo(0, 0);后默认在顶部了,但是用户调整布局后,我再动态添加后刷新一下布局ScrollView就又不在顶部了;我又在用户调整布局后,重新调用了一遍ScrollView.smoothScrollTo(0, 0);偶尔还是不在顶部;

2、我使用下面这种方法设置后,还是偶尔不能回到顶部;Handler的方法也是用过了,都不好用;

scrollView.post(new Runnable() {
@Override
public void run() {
scrollView_Owner.smoothScrollTo(0, 0);
}
});

3、我在ScrollView的外层布局(SwipeRefreshLayout)设置:

android:focusable="true"
android:focusableInTouchMode="true"

然后再RecyclerView的外层布局(LinearLayout)设置:

android:descendantFocusability="blocksDescendants"

完美解决!!!

有空来写一下LinearLayout动态添加布局;

附上代码:

<com.saicmaxus.common.widget.VpSwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mSwipeRefresh_Owner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="com.saicmaxus.maxuslife.fragment.OwnerFragment2">
<!--
解决srcollView不在顶部的问题
android:focusable="true"
android:focusableInTouchMode="true"
-->
<ScrollView
android:id="@+id/scrollView_Owner"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/llOwner"
android:descendantFocusability="blocksDescendants"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!--
解决srcollView不在顶部的问题
android:descendantFocusability="blocksDescendants"
-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <include
layout="@layout/view_is_not_owner"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</com.saicmaxus.common.widget.VpSwipeRefreshLayout>

ScrollView嵌套RecyclerView、ScrollView嵌套Listview、ScrollView嵌套各种布局,默认不在顶部和回到顶部的解决方法;的更多相关文章

  1. listview点击控件显示EditText,键盘弹出消失的解决方法:

    1.软键盘弹出后消失解决方法 AndoridManifet 在activity中添加: android:windowSoftInputMode="adjustPan" 2.使用方式 ...

  2. [Android Pro] ScrollView嵌套RecyclerView时滑动出现的卡顿

    reference to : http://zhanglu0574.blog.163.com/blog/static/113651073201641853532259/ ScrollView嵌套Rec ...

  3. Scrollview 嵌套 RecyclerView 及在Android 5.1版本滑动时 惯性消失问题

    标签:scrollview   android   滑动   嵌套 scrollview 嵌套recyclerview 时,recyclerview不显示,这就需要我们自己计算recyclerview ...

  4. ScrollView嵌套recyclerView出现的滑动问题

    记得以前在解决scrollView与ListView嵌套问题时,那个时候是自定义了listView去测量listView高度,今天项目中刚 好碰到了要用recycerView,同样也是嵌套在scrol ...

  5. 解决Scrollview 嵌套recyclerview不能显示,高度不正常的问题

    我们先看一个效果,问题说的就是中间的Grid效果在Scrollview 嵌套recyclerview显示问题,在Android Api 24是好的,不过在5,1,1版本(api 22)缺出现了问题 最 ...

  6. scrollview嵌套下拉控件嵌套recyclerview(不动第三方原基础自定义)

    相信会碰到很多类似的需求,一个列表控件,然后控件上方的一个头部需要自定义,这样就不好有时候也不能加在列表控件的头部了,那必须得嵌套一层scrollview了,没毛病,那么一般的列表控件都是有上拉下拉的 ...

  7. Android在开发中的使用技巧之解决ScrollView嵌套RecyclerView出现的系列问题

    根据已上线的app里总结出来的实用小技巧 相信大家都遇到过ScrollView嵌套RecyclerView或者RecyclerView嵌套RecyclerView来使用, 也会遇到一堆奇奇怪怪的问题, ...

  8. 关于ScrollView嵌套RecyclerView出现item显示不全的问题

    最近使用ScrollView时,发现里面嵌套Listview显示不全,试过重写Listview的onMeasure(),并没有起作用.然后将ListView换成RecyclerView后,高度还是显示 ...

  9. Android 解决ScrollView嵌套RecyclerView导致滑动不流畅的问题

    最近做的项目中遇到了ScrollView嵌套RecyclerView,刚写完功能测试,直接卡出翔了,后来通过网上查找资料和 自己的实践,找出了两种方法解决这个问题. 首先来个最简单的方法: recyc ...

随机推荐

  1. Qt开发问答

    Qt开发问答 1, Difference between Dialog and widget and QMainWindow http://www.qtcentre.org/threads/3465- ...

  2. enum和数据库entity互转

    注意,code和desc都是string的,数据库的entity是integer,dto的是enum,所以需要一个转换 entity转dto EnumGender.getEnum(String.val ...

  3. java直接量(literal)

    直接量就是代码中直接使用的值,如 int i = 7;  char c = 'a'; boolean b = false;  7.'a'.false就是直接量. java有三种类型的直接量:基本类型. ...

  4. Centos系统下Docker的安装

    一.检查内核版本 安装Docker,需要linux内核大于3.10 使用uname -r 来检查 二. Centos系统下Docker的安装 1. 安装需要的软件包 yum install -y yu ...

  5. 转:使用 Go-Ethereum 1.7.2搭建以太坊私有链

    使用 Go-Ethereum 1.7.2搭建以太坊私有链 目录 [toc] 1.什么是Ethereum(以太坊) 以太坊(Ethereum)并不是一个机构,而是一款能够在区块链上实现智能合约.开源的底 ...

  6. MySQL存储过程-->通过游标遍历和异常处理迁移数据到历史表

    -- 大表数据迁移,每天凌晨1点到5点执行,执行间隔时间10分钟,迁移旧数据到历史表. DELIMITER $$ USE `dbx`$$ DROP PROCEDURE IF EXISTS `pro_x ...

  7. Excel技巧--时尚的圆环比例图

    如上图,制作方法如下: 1.创建圆环图:选择表格,点击“插入”-->点击 圆环图. 2.删除图中的标题和标记,将圆环内径缩至最小: 3.复制表格的数据,重复两次粘贴到图表中: 4.依次选择内两环 ...

  8. SpringMVC-DispatcherServlet配置(Spring-servlet.xml)

    Spring-servlet.xml <context:component-scan base-package="com.spring.mvc.controller"/> ...

  9. Java 中统计文件中出现单词的次数练习

    统计英文article.txt文件中出现hello这个单词的次数 这个是article.txt文件内容 { hello The Royal Navy is trying hello to play h ...

  10. SpringCloud之实现客户端的负载均衡Ribbon(二)

    一 Ribbon简介 Ribbon是Netflix发布的负载均衡器,它有助于控制HTTP和TCP的客户端的行为.为Ribbon配置服务提供者地址后,Ribbon就可基于某种负载均衡算法,自动地帮助服务 ...