Android 片段不是从顶部开始的

Android 片段不是从顶部开始的,android,fragment,Android,Fragment,我的应用程序有两个带有viewpager的片段选项卡,它不是从顶部开始的,我不知道为什么。即使我将片段滚动到顶部,刷新(来回切换选项卡)也会将片段的开始位置重置在recyclerview的正上方 fragment2.xml <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:isScrollContainer="false

我的应用程序有两个带有viewpager的片段选项卡,它不是从顶部开始的,我不知道为什么。即使我将片段滚动到顶部,刷新(来回切换选项卡)也会将片段的开始位置重置在recyclerview的正上方

fragment2.xml

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:isScrollContainer="false"
android:layout_gravity="fill_vertical"
android:clipToPadding="false"
android:fillViewport="true"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="79dp"
            android:scaleType="fitXY"
            android:src="@drawable/sub4_visual"/>
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="79dp"
            android:alpha="0.3"
            android:background="#000000"/>
    </RelativeLayout>
    <TextView
        android:id="@+id/frag2_desc"
        android:layout_margin="11dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:textColor="@color/color_333333"
        android:text=""/>
    <Spinner
        android:id="@+id/frag2_dropbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:overScrollMode="ifContentScrolls"
        android:scrollbars="none"
        android:gravity="left"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_subfrag2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

Fragment2.java

    public class Fragment2 extends Fragment{

...

    public static Frag_BoardContent[] fragsList;
    public static RecyclerView mRecyclerView;
    public static Frag234_Adapter4 board_adapter;


    public Fragment2() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        final View v = inflater.inflate(R.layout.fragment2, container, false);

        tv_frag2Desc = (TextView) v.findViewById(R.id.frag2_desc);


        spinner = (Spinner) v.findViewById(R.id.frag2_dropbox);
        ArrayList<String> categoryList = new ArrayList<>();
        if (connect) makeDynamicArray(categoryList);
        adapter = new ArrayAdapter<> (getActivity(), R.layout.activity_board_spinner,categoryList);

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(final AdapterView<?> parent, final View view, int position, long id) {
                            mRecyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.context));
                            mRecyclerView.setHasFixedSize(true);
                            mRecyclerView.setNestedScrollingEnabled(false);
                            board_adapter = new Frag234_Adapter4(MainActivity.context, fragsList);
                            mRecyclerView.setAdapter(board_adapter);

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_subfrag2);
        mRecyclerView.setAdapter(board_adapter);



        return v;
    }

    public ArrayList<String> makeDynamicArray(){...}
}
公共类Fragment2扩展了Fragment{
...
公共静态框架内容[]框架列表;
公共静态回收视图mRecyclerView;
公共静态框架234_适配器4板_适配器;
公共碎片2(){
//必需的空公共构造函数
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片膨胀布局
最终视图v=充气机充气(右布局图碎片2,容器,假);
tv_frag2Desc=(TextView)v.findViewById(R.id.frag2_desc);
微调器=(微调器)v.findViewById(R.id.frag2_dropbox);
ArrayList categoryList=新的ArrayList();
if(connect)makedynamiccarray(categoryList);
adapter=new ArrayAdapter(getActivity(),R.layout.activity\u board\u微调器,categoryList);
spinner.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(最终适配器视图父视图、最终视图视图、整型位置、长id){
mRecyclerView.setLayoutManager(新的LinearLayoutManager(MainActivity.context));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setNestedScrollingEnabled(false);
board_adapter=新Frag234_Adapter4(MainActivity.context,fragsList);
mRecyclerView.setAdapter(单板适配器);
}
@凌驾
未选择公共无效(AdapterView父级){
}
});
mRecyclerView=(RecyclerView)v.findViewById(R.id.recycler_子片段2);
mRecyclerView.setAdapter(单板适配器);
返回v;
}
公共数组列表makeDynamicArray(){…}
}

这是一个关于焦点的问题。您需要对滚动视图执行
requestFocus()
,然后

setFocusable(false)


分裂

碎片不是从顶部开始的吗?什么意思?在fragment中,你第一次打开应用程序时没有加载,或者fragment加载,但顶部部分没有看到。发布你的查看页面和表格xmltop部分没有看到,在谷歌搜索了三个小时后,我在这里找到了答案:总是做研究,然后发布一个问题,节省您和其他人的时间。谢谢您的建议,但我认为这里的每个人在发布问题之前都会进行研究。如果我在三个小时的搜索后没有找到这个链接,我想其他人也会有同样的困难找到一个好的答案。我只是提供了另一种链接方法,以便有人可以看到我的问题,并到达与我相同的目的地。只是想帮助我自己和其他人。“链接帖子会让其他人更容易找到答案,我希望你也有过这样的经历。”DAgrawal说