ViewGroup.removeView(View view)&ViewGroup.removeViewAt(int index)

ViewPager里的ViewGroup.removeView(View view);与ViewGroup.removeViewAt有什么区别,为什么在自定义的PagerAdapter里destroyItem方法中,用前者没有错误,用后者,则会出现the specified child already have a parent .you must call removeView on the child‘parent first。#Android# #ViewPager#


API:


  • public void removeViewAt(int index)
    Removes the view at the specified position in the group.

    Note: do not invoke this method from View.draw(android.graphics.Canvas), View.onDraw(android.graphics.Canvas),dispatchDraw(android.graphics.Canvas) or any related method.

    Parameters:
    index - the position in the group of the view to remove





  • public void removeView(View view)

    Note: do not invoke this method from View.draw(android.graphics.Canvas), View.onDraw(android.graphics.Canvas),dispatchDraw(android.graphics.Canvas) or any related method.

    Specified by:
    removeView in interfaceViewManager




    ViewManager:
    • Interface to let you add and remove child views to an Activity. To get an instance of this class, call Context.getSystemService().



    所以removeView只是将view从activity里移除,而removeViewAt则是将view从ViewGroup里移除?

    ----------------------------------------------------------------------求交流--------------------------------------------------------------------------------------------

你可能感兴趣的:(android)