Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android视图组是否删除视图?_Java_Android - Fatal编程技术网

Java Android视图组是否删除视图?

Java Android视图组是否删除视图?,java,android,Java,Android,我有一只猫。该选项卡的活动之一是视图组。此视图组管理两个不同的活动。我这样做是为了在选项卡内的活动之间导航。我添加了如下活动: if (videoViewLive == null) videoViewLive = getLocalActivityManager().startActivity("VideoPlayerLive", new Intent(this,VideoPlayerLive.class). addFlags(Int

我有一只猫。该选项卡的活动之一是视图组。此视图组管理两个不同的活动。我这样做是为了在选项卡内的活动之间导航。我添加了如下活动:

if (videoViewLive == null)
            videoViewLive = getLocalActivityManager().startActivity("VideoPlayerLive", new Intent(this,VideoPlayerLive.class).
                    addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();

        videoViewLive.setVisibility(View.VISIBLE);
        this.addContentView(videoViewLive, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT));

我的每个内容视图活动都接收异步通知。我想做的是以某种方式删除未使用的活动/内容视图。所以在本质上,我加载内容视图A,B死亡,变为null,或者其他,反之亦然。我想这样做是因为我管理这些视图的方式似乎有问题。(加载一个视图、加载另一个视图、然后再次加载第一个视图时出错,等等)

您是否尝试过
ViewGroup.removeAllViews()

您是否尝试过
ViewGroup.removeAllViews()

这与这里的问题有点不相干,但您为什么要用单独的活动来实现这一点


这正是s设计的目的。实际上,中有一个名为include的类(另请参见),该类允许通过选项卡(可能在
操作栏中)或滑动来执行相同的行为。当您在
片段
之间导航时,适配器会自动处理它们的生命周期,所有这些都在单个
活动
的上下文中,这样您就可以使用顶级
活动
来路由事件,并在必要时维护总体状态。

这与这里的问题有点不相干,但你为什么要用不同的活动来做这件事呢


这正是s设计的目的。实际上,中有一个名为include的类(另请参见),该类允许通过选项卡(可能在
操作栏中)或滑动来执行相同的行为。当您在
片段
之间导航时,适配器会自动处理它们的生命周期,所有这些都在单个
活动
的上下文中,这样您就可以使用顶级
活动
路由事件,并在必要时维护总体状态。

我将尝试以下方法:

  //Add OnGlobalLayout Listener using ViewTreeObserver

View rootView = (android.R.id.content);

//Assuming you are managing these two activities inside the ViewGroup
Activity activityA = <someRef Value>;
Activity activityB = <someRef Value>;

rootView.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
    //try couple of things here
    // 1. determine which activity has focus
    // 2. you could also check position of View on screen to determine which one is active or on the top 
    if (activityA.hasWindowFocus())
    { 
       //do some action --remove other content from ViewGroup
    }
});
//使用ViewTreeObserver添加OnGlobalLayout侦听器
View rootView=(android.R.id.content);
//假设您在视图组中管理这两个活动
活动a=;
活动b=;
rootView.addOnGlobalLayoutListener(新的OnGlobalLayoutListener(){
//试试这里的一些东西
//1.确定哪些活动有重点
//2.您还可以检查屏幕上的视图位置,以确定哪个视图处于活动状态或位于顶部
if(activityA.hasWindowFocus())
{ 
//执行一些操作--从视图组中删除其他内容
}
});

我会尝试以下方法:

  //Add OnGlobalLayout Listener using ViewTreeObserver

View rootView = (android.R.id.content);

//Assuming you are managing these two activities inside the ViewGroup
Activity activityA = <someRef Value>;
Activity activityB = <someRef Value>;

rootView.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
    //try couple of things here
    // 1. determine which activity has focus
    // 2. you could also check position of View on screen to determine which one is active or on the top 
    if (activityA.hasWindowFocus())
    { 
       //do some action --remove other content from ViewGroup
    }
});
//使用ViewTreeObserver添加OnGlobalLayout侦听器
View rootView=(android.R.id.content);
//假设您在视图组中管理这两个活动
活动a=;
活动b=;
rootView.addOnGlobalLayoutListener(新的OnGlobalLayoutListener(){
//试试这里的一些东西
//1.确定哪些活动有重点
//2.您还可以检查屏幕上的视图位置,以确定哪个视图处于活动状态或位于顶部
if(activityA.hasWindowFocus())
{ 
//执行一些操作--从视图组中删除其他内容
}
});