1

I have a layout and try to make the components inside it scrollable, it shall be able to scroll the listView and Pdf-View and also it shall be able to scroll the ListView and Pdf-View together

<?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"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context=".uiFragments.HerstellerunterlagenInstandhalterFragment">

    <ScrollView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/back"
                android:layout_gravity="center_horizontal"
                android:orientation="vertical">

                <ListView
                    android:id="@+id/listview_anlagenuebersicht_instandhalter"
                    android:layout_marginTop="1dp"
                    android:layout_marginBottom="1dp"
                    android:layout_marginLeft="1dp"
                    android:layout_marginRight="1dp"
                    android:listSelector="@drawable/bkg"
                    android:background="@android:color/white"
                    android:layout_height="70dp"
                    android:layout_width="650dp"/>
            </LinearLayout>

            <com.github.barteksc.pdfviewer.PDFView
                android:id="@+id/pdfView_anlage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="100dp"/>

         </LinearLayout>
    </ScrollView>
</FrameLayout> 

I want to "scroll" my PDF-Viewer and Listview, together, but it does not work, I can only scroll my listView and the pdf-view separately

Josi Allen
  • 137
  • 2
  • 10

3 Answers3

1

You can use android:isScrollContainer="true". It will indicate that the view is one of the set of scrollable containers in its window. For more read this https://developer.android.com/reference/android/view/View

0

Because list view has its own scroll view you can not add it inside another scroll view so you must use them isolated

Reza M
  • 3
  • 3
0
  1. You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView. I strongly recommend you to simplify your layout somehow. For example you can add views you want to be scrolled to the ListView as headers or footers.

        UPDATE:
    
        Starting from API Level 21 (Lollipop) nested scroll containers are officially supported by Android SDK. There're a bunch
    

    of methods in View and ViewGroup classes which provide this functionality. To make nested scrolling work on the Lollipop you have to enable it for a child scroll view by adding android:nestedScrollingEnabled="true" to its XML declaration or by explicitly calling setNestedScrollingEnabled(true).

        If you want to make nested scrolling work on pre-Lollipop devices, which you probably do, you have to use corresponding
    

    utility classes from the Support library. First you have to replace you ScrollView with NestedScrollView. The latter implements both NestedScrollingParent and NestedScrollingChild so it can be used as a parent or a child scroll container.

        But ListView doesn't support nested scrolling, therefore you need to subclass it and implement NestedScrollingChild. Fortunately,
    

    the Support library provides NestedScrollingChildHelper class, so you just have to create an instance of this class and call its methods from the corresponding methods of your view class.

    ** More details : ListView inside ScrollView is not scrolling on Android