Reputation: 923
I've got a list of layouts that I need displayed on a PDF. However I'd like to find a way where I can combine these views into one view.
for(LinearLayout cardView : selectedCardIDList){
pageNo++;
cardView.measure(measuredWidth, 0);
cardView.layout(0, 0, pageWidth, cardView.getHeight());
cardView.draw(canvas);
}
This is the method I use to draw each view. I'd like to combine the views and then draw the new view.
Here's a quick example i drew up with 'V' being View.
On the left I have View 1 and View 2, I'd to try and stack them in a brand new view like View 3. Hope this helps
Here is an example of my problem.
private void generatePDF(){
PrintAttributes printAttributes = new PrintAttributes.Builder()
.setColorMode(PrintAttributes.COLOR_MODE_COLOR)
.setMediaSize(PrintAttributes.MediaSize.ISO_A4)
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
.setResolution(new PrintAttributes.Resolution("Res_Test", PRINT_SERVICE, 450, 700))
.build();
PdfDocument document = new PrintedPdfDocument(getActivity(), printAttributes);
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(595,842,1).create();
PdfDocument.Page page = document.startPage(pageInfo);
for(LinearLayout cardView : selectedCardIDList){
((ViewGroup)cardView.getParent()).removeView(cardView);
combiPDfView.addView(cardView);
}
combiPDfView.draw(canvas);
document.finishPage(page);
}
This is the method I'm using to generate the PDF.
<LinearLayout
android:id="@+id/pdfView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible"/>
This is the layout that I've made to add views to and display on the PDF. combiPDfView is the name of the LinearLayout.
Upvotes: 0
Views: 338
Reputation: 3265
You can implement this by using this:
Take a parent Linearlayout with the orientation vertical
LinearLayout parentView= findViewById(R.id.parentView);
code to add the view
for(LinearLayout cardView : selectedCardIDList){
// View to be added
pageNo++;
cardView.measure(measuredWidth, 0);
cardView.layout(0, 0, pageWidth, cardView.getHeight());
cardView.draw(canvas);
//add view to parent view
parentView.addView(cardView);
}
Upvotes: 1