0

enter code hereMy root layout is nested scroll view inside nested scroll view create viewpager for changes pdf left to right, or right to left it works properly but when scroll pdf up down for change pdf view so that not work properly.

What I want:- I want to when click next and previous arrow so pdf are change and when scroll up down so change pdf inside content

my code flow is like (kotlin):- (1) create single item design in design i took barteksc pdf view. (2) create Adapter for class,model class for pdf view (3) set adapter in viewpager

barteksc:android-pdf-viewer:2.8.2 I used this dependency

Note:- without nested scroll view it will work perfect but I want with scroll view.

Thanks.enter image description here

activity_main.xml

<androidx.core.widget.NestedScrollView 
        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="wrap_content"
        android:background="@color/listing_background"
         android:id="@+id/scrolview_parrent"
        tools:context=".view.activity.ListingActivity">

      <LinearLayout
        android:id="@+id/linear_viewing_area"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_180sdp"
        android:layout_below="@id/linear_export_excel"
        android:orientation="vertical"
        android:layout_marginBottom="@dimen/_15sdp"
        android:background="@drawable/viewing_area_bg"
        android:layout_marginStart="@dimen/_10sdp"
        android:layout_marginEnd="@dimen/_10sdp"
        android:padding="@dimen/_5sdp"
        android:visibility="visible"
        android:layout_marginTop="@dimen/_15sdp">

      
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/pdf_view_bg">

            <androidx.viewpager.widget.ViewPager
                android:nestedScrollingEnabled="false"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/viewpager_for_pdf_listing"
                android:layout_centerInParent="true"
                android:clipToPadding="false"
                android:foregroundGravity="center" />


            <ImageView
                android:id="@+id/img_next_listing"
                android:layout_width="@dimen/_40sdp"
                android:layout_height="35dp"
                android:src="@drawable/fws"
                android:layout_marginEnd="@dimen/_100sdp"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="5dp"
                android:paddingTop="5dp"
                android:paddingBottom="5dp"
                />


            <ImageView
                android:id="@+id/img_previous_listing"
                android:layout_width="@dimen/_40sdp"
                android:layout_height="35dp"
                android:src="@drawable/back"
                android:layout_centerVertical="true"
                android:layout_marginStart="@dimen/_100sdp"
                android:layout_alignParentLeft="true"
                android:paddingTop="5dp"
                android:paddingBottom="5dp"/>
        </RelativeLayout>
    </LinearLayout>
   </androidx.core.widget.NestedScrollView>

single item design xml.

enter code here
    <RelativeLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:background="@color/pdf_view_bg"
   android:layout_height="match_parent">

<com.github.barteksc.pdfviewer.PDFView
    android:id="@+id/pdfview"
    android:nestedScrollingEnabled="false"
    android:layout_width="@dimen/_189sdp"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:layout_marginTop="@dimen/_15sdp"
    android:layout_marginBottom="@dimen/_15sdp"
    android:padding="@dimen/_5sdp" />

Adapter Class

enter code here
        class PdfAdapter(private val context: Context, private val pdfList: ArrayList<PdfModel>) :
PagerAdapter() {
override fun getCount(): Int {

    return pdfList.size

}

override fun isViewFromObject(view: View, `object`: Any): Boolean {
    return view == `object`
}


override fun instantiateItem(container: ViewGroup, position: Int): Any {

    val view = LayoutInflater.from(context)
        .inflate(R.layout.single_row_design_for_pdfview, container, false)

    val model = pdfList[position]
    val pdfview = model.pdf

    //set datato ui view
    view.pdfview.fromStream(pdfview).load()
    view.pdfview.isNestedScrollingEnabled
    container.addView(view, position)
    return view
}


override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
    container.removeView(`object` as View)
}
}

MainActivity Class

enter code here
    private fun loadPdf() {
    pdfModel = ArrayList()

    pdfModel.add(PdfModel(assets.open("AI1.pdf")))
    pdfModel.add(PdfModel(assets.open("AI2.pdf")))
    pdfModel.add(PdfModel(assets.open("AI3.pdf")))

    // setup adapter
    pdfAdapter = PdfAdapter(this, pdfModel)

    //set adapter to viewpager
    viewpager_for_pdf_listing.adapter = pdfAdapter

    // set default padding

    viewpager_for_pdf_listing.setPadding(60, 0, 60, 0)

    //disable view pager swipe.
    //only swipe when click buttun
    viewpager_for_pdf_listing.setOnTouchListener { v, event -> true }
    
}
Kamal Nayan
  • 1,635
  • 1
  • 5
  • 19

0 Answers0