Reputation: 11
Description: I’m building a PDF reader app similar to WPS PDF Reader and need help achieving the following behavior:
The PDFView should allow the user to scroll through the entire PDF document.
After scrolling to the last page of the PDF, the user can continue scrolling down, and an AdMob Banner Ad should appear below the PDF content.
3.The entire scroll, including the banner, should feel smooth and continuous, as seen in WPS PDF Reader.
here is the video preview of what I want: https://www.dropbox.com/scl/fi/k1w1n1xngsph664q1grfs/Screenrecorder-2024-12-15-19-10-15-641.mp4?rlkey=e7fgkab41rc5wxj9bhdqj3m2x&st=j9af8kme&dl=0
Current Layout: Here’s the XML layout I’m working with:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/pdf_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<!-- Toolbar -->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_home"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/background_color_day_night"
android:elevation="2dp" />
<!-- Main Content -->
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPDFViewBg" />
<ProgressBar
android:id="@+id/progress_bar_open_pdf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateTint="@color/tint_color" />
</RelativeLayout>
<!-- Banner Ad -->
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
What I’ve Tried:
I used a combination of RelativeLayout and LinearLayout, but the BannerView is displayed alongside the PDF content instead of below it.
I attempted wrapping the PDFView inside a NestedScrollView, but this breaks the PDFView scrolling functionality since it doesn’t handle nested scrolls well.
The banner either overlaps the PDF content or remains fixed at the bottom.
Expected Behavior: The user should experience:
A scrollable PDF that behaves normally.
When scrolling past the last page of the PDF, a banner ad should appear below the PDF content.
The scrolling should remain fluid and responsive throughout.
Upvotes: 0
Views: 26