2014-02-19 130 views
0

我试图让自己的基本'帮助覆盖'。我已经实现了这么多目前为止Take a lookAndroid addView StackOverFlow错误

这是通过调用addContentView与传入的自定义视图的实例完成的。但是,我将只能隐藏自定义视图,而不是在完成后完全删除它它。

到目前为止,这是非常基本的,所以没有天才或pizazz呢。我正在努力进一步改进其易用性。 https://stackoverflow.com/a/10217050/3194316此堆栈溢出答案建议将内容视图设置为动态创建的Framelayout并使视图膨胀。我已经添加了代码

FrameLayout layout = new FrameLayout((Context) activity); 
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
     ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
layout.setLayoutParams(layoutParams); 

View parentView = activity.getWindow().getDecorView().findViewById(android.R.id.content); 
((ViewGroup) parentView.getParent()).removeAllViews(); 
activity.setContentView(layout); 

layout.addView(parentView); 
layout.addView(this); 

其中this是设定如下所示的覆盖自定义视图的一个实例。 activity是其中介绍的活动的一个实例。我最初得到parentView已经有父母的错误,所以这就是为什么View parentView = activity.getWindow().getDecorView().findViewById(android.R.id.content); ((ViewGroup) parentView.getParent()).removeAllViews();被添加的原因。我现在不幸地收到堆栈溢出错误,我似乎无法理解为什么。有没有更好的方法来处理这种情况?

SOLUTION

在弹出窗口结束语一切都使得整个覆盖到正确的Android系统被解雇。

FrameLayout layout = new FrameLayout(context.get()); 
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
     ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
layout.setLayoutParams(layoutParams); 

LayoutInflater inflater = (LayoutInflater) context.get().getSystemService(
     Context.LAYOUT_INFLATER_SERVICE); 

View overlayBase = inflater.inflate(R.layout.help_frame, null, false); 
layout.addView(this); 
layout.addView(overlayBase); 

popupWindow = new PopupWindow(context.get()); 
popupWindow.setContentView(layout); 
popupWindow.setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT, 
     ViewGroup.LayoutParams.MATCH_PARENT); 
popupWindow.showAtLocation(this, Gravity.CENTER, 0, 0); 

背景是自定义视图中的一流水平WeakReference的变量,在构造函数被调用

如果有人有兴趣实例,这里是我用来创建popupwindow

这里的代码是(非最终)结果Take a look

+0

我没有得到你想要达到的目标,但是你做错了。你考虑过PopupWindow吗? –

+0

基本上突出显示屏幕上的某个元素[见这里](http://acko.net/files/android/app-drawer.png)。说实话,我并不知道弹出窗口。看起来很有趣。 – rperryng

+0

上面的屏幕截图只是一个全屏ImageView覆盖。无论如何,看看PopupWindow。据我所知,你需要显示一个挂钩到一个视图。这就是它的作用。 –

回答