这是我的片段,我在其中调用了Recycler View:
我希望我的Recycler视图从顶部项开始显示,而不是从中间项开始。有人能告诉我应该在我的代码中做哪些更改吗?提前感谢。
我的意思是这样的:
public class sgpa_frag extends Fragment {
//View view;
RecyclerView recyclerview;
adapter_sgpa ac;
ArrayList<POJO> sgpaArrayList;
public sgpa_frag() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sgpa_frag, container, false);
recyclerview= (RecyclerView) view.findViewById(R.id.rc1);
sgpaArrayList= new ArrayList<>();
ac= new adapter_sgpa(sgpaArrayList);
recyclerview.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,true));
recyclerview.setAdapter(ac);
Fetchdata1();
return view;
}
private void Fetchdata1()
{
dbmanager db= new dbmanager(getContext());
Cursor cursor= db.fetch_data1();
if (cursor!= null){
// cursor.moveToFirst();
while (cursor.moveToNext()){
POJO pj= new POJO();
pj.setSname(cursor.getString(0));
pj.setSemester(cursor.getString(1));
pj.setSgpa(cursor.getString(2));
pj.setPercent(cursor.getString(3));
pj.setSchemes(cursor.getString(4));
sgpaArrayList.add(pj);
}
ac= new adapter_sgpa(sgpaArrayList);
}
}
}
这是我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".drawernav.bottom_navi.recycler_view.sgpa_frag">
<!-- TODO: Update blank fragment layout -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rc1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="60dp">
</androidx.recyclerview.widget.RecyclerView>
</FrameLayout>
我希望我的Recycler视图从顶部项开始显示,而不是从中间项开始。有人能告诉我应该在我的代码中做哪些更改吗?提前感谢。
我的意思是这样的:
我希望它是这样的: