0

我有一个想要扩展为全屏的 WebView。用户将与它进行交互,因此它需要在扩展时保持某种状态。理想的过程是这样的:

- Remove WebView from its parent
- Put WebView at the top of the current View hierarchy with `FILL_PARENT` for width and height

稍后,我需要把 WebView 放回去:

- Remove WebView from top of the hierarchy
- Restore the old hierarchy
- Put WebView back where it was with its previous setting for width and height

我知道getRootView,但我不知道如何使用它。什么是DecorView

如果有人有一些示例代码来完成我上面描述的扩展和折叠行为,我将不胜感激。谢谢!

4

1 回答 1

2

获取的根视图DecorView

ViewGroup parentViewGroup = (ViewGroup) webView.getRootView().findViewById(android.R.id.content);
View rootview = parentViewGroup.getChildAt(0);

删除该根视图:

parentViewGroup.removeViewAt(0);

WebView从其父级中删除:

View webViewParent = (View) webView.getParent();
webViewParent.removeView(webView);

将 放在WebView视图层次结构的顶部:

parentViewGroup.addView(webView, 0, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT));

使用您的rootview参考来撤消扩展。

唯一的事情是:我不知道您将如何恢复rootview.

于 2012-10-15T05:17:49.690 回答