【问题标题】:Android ViewStub manage replace inner ViewsAndroid ViewStub 管理替换内部视图
【发布时间】:2017-07-18 09:42:53
【问题描述】:

我正在使用ViewStub Android 组件进行测试。我可以给View 充气并用新的替换,但是当我用新的替换现有的View 时,我怀疑驱逐舰永远不会在旧的替换视图中调用。这是我的逻辑的示例代码:

protected void testInflateReplaceViewStub(){
    //case inflating a View...
    View viewInflated = View.inflate(getContext(), R.layout.container_view, this); //container View
    ViewStub viewStub = (ViewStub) findViewById(R.id.view_stub_impl); //view inside layout
    viewStub.setLayoutResource(R.layout.container_view); //fill with some content
    View viewStubInflated = viewStub.inflate();
    //end inflating the first ViewStub

    //case replacing above View by a new one...
    viewStubInflated.invalidate(); //this should destroy old inner Views??
    viewInflated = View.inflate(getContext(), R.layout.container_view, this);
    viewStub.setLayoutResource(R.layout.new_content);//fill new content
    viewStubInflated = viewStub.inflate();
    //end replacing inflating
}

我想强制销毁所有旧替换的Views

【问题讨论】:

    标签: android android-inflate viewstub


    【解决方案1】:

    一个你膨胀的ViewStub它会从层次结构中消失,你不能再次使用它:

    在布局资源“mySubTree”膨胀后,ViewStub 是 从其父级中删除。

    ViewStub documentation

    尝试使用include 甚至FrameLayout,取决于您的需要。

    【讨论】:

      猜你喜欢
      • 2015-08-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多