AndroidPdfViewer
AndroidPdfViewer copied to clipboard
Inflating a pdfview and adding it programmatically to another view.
Hi there everyone.
I'm trying to inflate a PDFView in another view programmatically, since it depends on certain values if I show it or not. The thing is my PDFView only shows an encased "1" in something that seems like a button.
This is my code. LastID is just an integer that increments whenever you put something more in the view, so you can put them dinamically one below another:
onCreate
`
LayoutInflater inflater = this.getLayoutInflater();
vistaPDF = (PDFView) inflater.inflate(R.layout.pdf_view, null);
RelativeLayout.LayoutParams presupuestoParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, MATCH_PARENT);
presupuestoParams.addRule(RelativeLayout.BELOW, lastId);
vistaPDF.setLayoutParams(presupuestoParams);
vistaPDF.setId(lastId+1);
vistaPDF.fromAsset("Llamegar.pdf")
.defaultPage(0)
.enableSwipe(true)
.swipeHorizontal(false)
.onPageChange(this)
.enableAnnotationRendering(true)
.onLoad(this)
.scrollHandle(new DefaultScrollHandle(this))
.load();
vistaRelativa.addView(vistaPDF);
`
pdf_view.xml
<?xml version="1.0" encoding="utf-8"?> <com.github.barteksc.pdfviewer.PDFView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent"/>
I honestly don't know if I'm missing something or if I'm just plain dumb.
Thank you very much for your help in advice!