Add a custom view to a PDF page in Xamarin
CustomRelativeLayout is a RelativeLayout that can be nested under PDFViewCtrl with a given page position and page number. All child views of CustomRelativeLayout are displayed on top of PDFViewCtrl. When PDFViewCtrl is scrolling or zooming, CustomRelativeLayout will adjust position and size automatically according to the app:zoomWithParent attribute.

Show CustomRelativeLayout
You can add CustomRelativeLayout as a child view of PDFViewCtrl in your XML layout resource file:
Add custom layout from separate layout file
Alternatively, you can also add CustomRelativeLayout from separate layout file. Here is an example where the CustomRelativeLayout is inflated and added directly to PDFViewCtrl.
Define an XML layout resource file containing a
CustomRelativeLayout. For example, our layout fileR.layout.custom_layout_textviewshown below contains aCustomRelativeLayoutwith two child views:
Then you can inflate the layout and add it directly to
PDFViewCtrl:
Add custom layout programmatically
You can also add the custom layout programmatically. The code below uses CustomRelativeLayoutconstructor to create a custom layout equivalent to previous examples:
XML attributes
CustomRelativeLayout allows child views to be displayed inside PDFViewCtrl. XML attributes for positioning CustomRelativeLayout in PDFViewCtrl are defined in the table below:
app:posX
Specifies the x-coordinate in PDF page coordinates . Default value: 0
app:posY
Specifies the y-coordinate in PDF page coordinates . Default value: 0
app:pageNum
Specifies the page number of the document that will contain this CustomRelativeLayout. Default value: 1
app:zoomWithParent
Specifies whether the CustomRelativeLayout will zoom with parent. Default value: true
android:layout_width
Specifies the width of the view, it must be a positive integer in PDF page coordinates .
android:layout_height
Specifies the height of the view, it must be a positive integer in PDF page coordinates .
Last updated
Was this helpful?