ScrollView中页面显示自动滑到最后问题的解决

原因,ScrollView中包含其余控件,但控件显示不全,此时会存在焦点问题,布局显示回到最后

解决方法:

    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >
            android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
重点是:

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

这么做后发现切换界面后还是有这个问题于是:

此问题一开始我以为是我在fragment当中,返回和移动的时候调用了adpaternotifyItemChange方法情况和notifyItemChanged(int position) 引起的返回时RecyclerView页面不自然的跳动 一样,但是发现我并没有调用过此方法,所以我想是不是有可能是子 recyclerView 抢了焦点导致子 RecyclerView自动滚动到了第一行,所以我在子recyclerView设置

recycler_mine_partake_message.setFocusableInTouchMode(false); //设置不需要焦点
recycler_mine_partake_message.requestFocus(); //设置焦点不需要
  • 1
  • 2

同时我想到了在ScrollView当中同样会出现这个问题 ,解决思路:

    在代码里面 让处于ScrollView或者RecyclerView1 顶端的某个控件获得焦点即可
    比如顶部的一个textview
    tv_goodsName.setFocusableInTouchMode(true);  
    tv_goodsName.requestFocus(); 

你可能感兴趣的:(android)