简体   繁体   中英

Recyclerview Elements get cut off at the end of the screen

I'm trying to show a list of people using Recyclerview. But the List just gets cut off at the end of the screen. If i change the layout more people are shown but it still gets cut off at the end of the screen

The first list should have 12 Elements whereas it only shows the 9 / 10 elements which are initially visible even though the rest of the elements should be visible if I scroll down. If the recyclerview is initially completely invisible(see the second one) then all elements can be seen on scrolling.

Images:

https://ibb.co/kg2q03H

https://ibb.co/19YgXT9

https://ibb.co/0f03GKH

https://ibb.co/3vpgQSp

<ScrollView
        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"
        tools:context=".ViewDetails" android:scrollbarSize="0dp"
>
    <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
                  android:orientation="vertical">
        <TableLayout android:layout_height="wrap_content"
                     android:layout_width="match_parent" android:id="@+id/table">
            <TableRow android:layout_width="match_parent" android:layout_height="match_parent">
                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" android:layout_gravity="left">
                    <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp" android:id="@+id/name" android:layout_weight="1"
                            android:layout_margin="16dp" app:srcCompat="@drawable/wappentransparent"/>
                    <TextView
                            android:text="Musikprobe"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" android:id="@+id/nameText"
                            android:layout_gravity="center_vertical" android:textSize="24sp"
                            android:layout_margin="8dp" android:textColor="@color/primaryTextColor"
                    />
                </LinearLayout>
            </TableRow>
            <TableRow android:layout_width="match_parent" android:layout_height="match_parent">
                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" android:layout_gravity="left">
                    <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp" android:id="@+id/date" android:layout_weight="1"
                            android:layout_margin="16dp" app:srcCompat="@drawable/ic_date_range"/>
                    <TextView
                            android:text="01.01.2000"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" android:id="@+id/dateText"
                            android:layout_gravity="center_vertical" android:textSize="18sp"
                            android:layout_margin="8dp" android:textColor="@color/primaryTextColor"/>
                </LinearLayout>
            </TableRow>
            <TableRow android:layout_width="match_parent" android:layout_height="match_parent">
                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" android:layout_gravity="left">
                    <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp" android:id="@+id/time" android:layout_weight="1"
                            android:layout_margin="16dp" app:srcCompat="@drawable/ic_schedule_black_24dp"/>
                    <TextView
                            android:text="12:00"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" android:id="@+id/timeText"
                            android:layout_gravity="center_vertical" android:textSize="18sp"
                            android:layout_margin="8dp" android:textColor="@color/primaryTextColor"/>
                    <TextView
                            android:text="Uhr"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" android:id="@+id/uhrConst"
                            android:layout_gravity="center_vertical" android:textSize="18sp"
                            android:layout_marginTop="8dp"
                            android:layout_marginBottom="8dp" android:textColor="@color/primaryTextColor"/>
                </LinearLayout>
            </TableRow>
            <TableRow android:layout_width="match_parent" android:layout_height="match_parent"
                      android:id="@+id/infoTabRow">
                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" android:layout_gravity="left">
                    <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp" android:id="@+id/info" android:layout_weight="1"
                            android:layout_margin="16dp" app:srcCompat="@drawable/ic_event_note"/>
                    <TextView
                            android:text="Hier steht ganz viel info und so"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" android:id="@+id/infoText"
                            android:layout_gravity="center_vertical" android:textSize="18sp"
                            android:layout_margin="8dp" android:textColor="@color/primaryTextColor"/>
                </LinearLayout>
            </TableRow>

            <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                <View
                        android:id="@+id/divider"
                        android:layout_width="wrap_content"
                        android:layout_height="1dp"
                        android:background="?android:attr/listDivider"
                />
            </TableRow>

            <TableRow>

                <androidx.constraintlayout.widget.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">

                    <Button
                            android:id="@+id/signOut"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:backgroundTint="@android:color/holo_red_light"
                            android:text="ABMELDEN"
                            app:layout_constraintStart_toEndOf="@+id/signUp"
                            app:layout_constraintTop_toTopOf="parent"
                            app:layout_constraintBottom_toBottomOf="parent"/>
                    <Button
                            android:id="@+id/signUp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:backgroundTint="@android:color/holo_green_light"
                            android:text="ANMELDEN"
                            app:layout_constraintTop_toTopOf="parent"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"/>
                </androidx.constraintlayout.widget.ConstraintLayout>
            </TableRow>

            <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                <View
                        android:id="@+id/divider2"
                        android:layout_width="wrap_content"
                        android:layout_height="1dp"
                        android:background="?android:attr/listDivider"
                />
            </TableRow>

            <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"
                      android:id="@+id/signedInHeader">
                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" android:layout_gravity="left">
                    <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp" android:id="@+id/signedUp" android:layout_weight="1"
                            android:layout_margin="16dp" app:srcCompat="@drawable/ic_people_green"/>
                    <TextView
                            android:id="@+id/teilnehmer"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:textSize="24sp"
                            android:layout_margin="8dp"
                            android:text="Teilnehmer" android:textColor="@color/primaryTextColor"
                            android:layout_gravity="center_vertical"/>

                </LinearLayout>
            </TableRow>


            <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvTeilnehmer"
                    android:layout_width="match_parent"
                    android:layout_marginLeft="56dp"
                    android:layout_marginStart="56dp" android:layout_height="match_parent"/>
            <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"
                      android:id="@+id/signedOutHeader">
                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" android:layout_gravity="left">
                    <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp" android:id="@+id/signedOut" android:layout_weight="1"
                            android:layout_margin="16dp" app:srcCompat="@drawable/ic_people_red"/>
                    <TextView
                            android:id="@+id/abgesagt"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:textSize="24sp"
                            android:layout_margin="8dp"
                            android:text="Abgesagt" android:textColor="@color/primaryTextColor"
                            android:layout_gravity="center_vertical"/>

                </LinearLayout>
            </TableRow>


            <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvAbgesagt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" android:layout_marginLeft="56dp"
                    android:layout_marginStart="56dp"/>
        </TableLayout>
    </FrameLayout>
</ScrollView>

        rvsi = view.findViewById(R.id.rvTeilnehmer)
        val llmsi = object : LinearLayoutManager(context) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        rvsi!!.layoutManager = llmsi
        rvsi!!.adapter = RVPersonAdapter(PersonList().persons)
//PersonList().person is an arraylist of 12 Persons(which contain a String with the name)

Based on your updated post, it seems you may be having an issue with nested scrolling. See RecyclerView inside ScrollView is not working .

The gist of it is that you will need to replace your ScrollView with a NestedScrollView and then set a flag in your RecyclerViews to allow it to scroll properly.

If you don't use the NestedScrollView, the parent ScrollView will intercept all of the scroll events instead of sending them to the RecyclerViews - so the items are technically there in the recyclers, you just can't get to them.

Think about using multi-view type RecyclerView rather than RecyclerView in ScrollView. You can use NestedScrollView+RecyclerView as @VerumCH suggested above (also you should disable nested scrolling by setting nestedScrollingEnabled attribute of RecyclerView as false), but there is another problem. If you will use RecyclerView in NestedScrollView, list views will not be recycled & will be given you at once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM