Я пытаюсь добавить много Frame Layout к активности.Это выглядит так:
фото1
фото2
Сколько будет отображаться на экране, зависит от разрешения экрана, поэтому яхотел бы добавить более десятка фрагментов и сделать прокрутку активности.Я хочу, чтобы это выглядело как представление списка.На данный момент у меня есть несколько Frame Layout и добавляет фрагменты один за другим.Если у кого-то есть идея, как это сделать, пожалуйста, помогите мне.Спасибо.
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment s1 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
FrameLayout container = findViewById(R.id.fragmentContainer);
fragmentTransaction.add(R.id.fragmentContainer, s1);
fragmentTransaction.commit();
Fragment s2 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction2 = fragmentManager.beginTransaction();
fragmentTransaction2.add(R.id.fragmentContainer2, s2);
fragmentTransaction2.commit();
FrameLayout container2 = findViewById(R.id.fragmentContainer2);
Fragment s3 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction3 = fragmentManager.beginTransaction();
fragmentTransaction3.add(R.id.fragmentContainer3, s3);
fragmentTransaction3.commit();
FrameLayout container3 = findViewById(R.id.fragmentContainer3);
Fragment s4 = new SingleCourseFragment();
FragmentTransaction fragmentTransaction4 = fragmentManager.beginTransaction();
fragmentTransaction4.add(R.id.fragmentContainer4, s4);
fragmentTransaction4.commit();
FrameLayout container4 = findViewById(R.id.fragmentContainer4);
container.setVisibility(View.VISIBLE);
container2.setVisibility(View.VISIBLE);
container3.setVisibility(View.VISIBLE);
container4.setVisibility(View.VISIBLE);
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<EditText
android:id="@+id/startET"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:inputType="text"
android:layout_margin="20dp"
android:enabled="false"
android:gravity="center"
android:background="@drawable/rounded_border_edittext"
android:hint="@string/start"/>
<EditText
android:id="@+id/endET"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/startET"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:enabled="false"
android:gravity="center"
android:background="@drawable/rounded_border_edittext"
android:inputType="text"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragmentContainer"
android:layout_below="@+id/endET"
android:visibility="invisible">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragmentContainer2"
android:layout_below="@+id/fragmentContainer"
android:visibility="invisible">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragmentContainer3"
android:layout_below="@+id/fragmentContainer2"
android:visibility="invisible">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragmentContainer4"
android:layout_below="@+id/fragmentContainer3"
android:visibility="invisible">
</FrameLayout>
</RelativeLayout>