孩子的父母打电话removeView()第一 [英] Call removeView() on the child's parent first

查看:203
本文介绍了孩子的父母打电话removeView()第一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先一点背景:

我有一个滚动视图里的布局。首先,当在屏幕上的用户滚动,滚动视图滚动。但是,一定量的滚动后,我禁用滚动的滚动视图的举动滚动焦点到里面的子布局的一个web视图。通过这种方式,滚动视图棍棒和所有的滚动事件到web视图里面。

I have a layout inside a scrollview. At first, when the user scrolls on the screen, the scrollview scrolls. However, after a certain amount of scroll, I was to disable the scroll on the scroll view the move the "scroll focus" onto a webview inside the child layout. This way, the scrollview sticks and all the scroll events go to the webview inside it.

所以,一个解决方案,当达到滚动阈值时,我从滚动视图中删除的子布局,并把它放在滚动视图的母公司。(并进行滚动视图不可见)。

So, for a solution, when the scroll threshold is reached, I remove the child layout from the scrollview and put it in scrollview's parent.(And make the scrollview invisible).

// Remove the child view from the scroll view
scrollView.removeView(scrollChildLayout);

// Get scroll view out of the way
scrollView.setVisibility(View.GONE);

// Put the child view into scrollview's parent view
parentLayout.addView(scrollChildLayout);

总体思路:( - >工具包含)

General Idea: (-> means contains)

在:parentlayout - >滚动视图 - > scrollChildLayout

Before: parentlayout -> scrollview -> scrollChildLayout

在:parentLayout - > scrollChildLayout

After : parentLayout -> scrollChildLayout

以上code是给我这个异常:

The above code is giving me this exception:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
           at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
           at android.view.ViewGroup.addView(ViewGroup.java:1871)
           at android.view.ViewGroup.addView(ViewGroup.java:1828)
           at android.view.ViewGroup.addView(ViewGroup.java:1808)

你知不知道这是怎么回事?我清楚父叫removeView。

Do you know what's going on? I am clearly calling removeView on the parent.

推荐答案

解决方法:

((ViewGroup)scrollChildLayout.getParent()).removeView(scrollChildLayout);
//scrollView.removeView(scrollChildLayout);

使用子元素来获得一个引用父。投亲到的ViewGroup,让你得到访问removeView方法和使用。

Use the child element to get a reference to the parent. Cast the parent to a ViewGroup so that you get access to the removeView method and use that.

感谢@Dongshengcn的解决方案

Thanks to @Dongshengcn for the solution

这篇关于孩子的父母打电话removeView()第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆