2015-11-05 51 views
0

我正在给一个ViewGroup充气以导出为PDF文档。从xml文件中填充它后,我用图像和文本填充它。现在,当我尝试在PDF页面的画布中绘制此ViewGroup时,VieGroup的高度为零。画布是空的。等待视图完全更新:如何?

这是代码:

View pdfRowLayout = ltInflater.inflate(R.layout.pdf_export_row_layout, 
        (ViewGroup) parent, false); 

      TextView action = (TextView) pdfRowLayout.findViewById(R.id.pdf_action_field); 
      action.setText(host.getDataProvider().getChildItem(curGroupPosition, 1).getText()); 

      ImageView avatar = (ImageView) pdfRowLayout.findViewById(R.id.pdf_avatar); 
      avatar.setImageBitmap(host.getDataProvider().getGroupItem(curGroupPosition).getGroupImage()); 

我明白,我需要等待,直到布局是与特定的听众完全充气。但是,我是否必须等待所有数据才能调整布局大小?

+1

请参阅[this](http://stackoverflow.com/questions/4680499/how-to-get-the-width-and-height-of-an-android-widget-imageview)post获取视图的宽度/运行时的高度。 –

回答

0

您可以简单地使用片段/活动的onResume()侦听器,此方法使片段/活动开始与用户交互,这意味着该片段对用户完全可见。

+0

这是不正确的。在'onResume()'中,视图还没有布置。 – Onik

+0

你能否在你的问题中提供一些代码,你已经完成了什么以及“如何用图像和文本填充你的xml文件”,因为在onStart中,特别是在onResume中你的片段和活动全部可见 –

+0

看一看[this回答](http://stackoverflow.com/questions/3591784/getwidth-and-getheight-of-view-returns-0/24035591#24035591) – Onik