【发布时间】:2021-12-26 08:41:57
【问题描述】:
当我在片段之间切换时,我一直在尝试在片段中实现 recyclerview,如图所示,recyclerview 的大小正在减小
下面给出的代码我没有用户recyclerview.setHasFixedSize(true);故意的,因为如果我使用它,它不会从数据库中检索数据,从而使 recyclerview 为空
XML 代码
?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="@color/apptheme"
android:orientation="vertical"
tools:context=".ProgrammesAndSubjects.Subjects_Under_ProgrammeFragment">
<TextView
android:id="@+id/add_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="@dimen/_7sdp"
android:layout_marginTop="@dimen/_7sdp"
android:includeFontPadding="false"
android:text="Add \n Subjects"
android:textAlignment="center"
android:textColor="@color/appcolor"
android:textSize="@dimen/_12sdp"
android:textStyle="bold"
tools:ignore="RtlCompat" />
<ProgressBar
android:id="@+id/top_class"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:outlineSpotShadowColor="@color/white" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView_classes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/_6sdp"
android:padding="10dp"
android:divider="@null"
android:scrollbars="vertical" />
<ProgressBar
android:id="@+id/bottomprogressbar_classes"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="-40dp"
android:outlineSpotShadowColor="@color/white" />
</LinearLayout>
JAVA 代码
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
addsubjects = getView().findViewById(R.id.add_subject);
progressBar = getView().findViewById(R.id.top_class);
bottomProgressbar = getView().findViewById(R.id.bottomprogressbar_classes);
recyclerView = getView().findViewById(R.id.recyclerView_classes);
RecyclerView.LayoutManager mlayoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(mlayoutManager);
}
**它有一个已设置的普通适配器**
【问题讨论】:
标签: android android-fragments android-recyclerview