简体   繁体   English

当我显示片段时,下面的对象仍会响应点击

[英]When I show a fragment the objects below still respond to clicks

I have some fragments that are part of a view pager. 我有一些片段是视图寻呼机的一部分。 Those work fine. 那些工作正常。 However, on top of the fragments in the view pager, I want to put fragments on top of them (ie nested or child fragments). 但是,在视图分页器中的片段之上,我想将片段放在它们之上(即嵌套片段或子片段)。 So, in OnCreateView of the parent fragment, I go ahead and declare my child fragment but then hide it right away. 因此,在父片段的OnCreateView中,我继续声明我的子片段,然后立即将其隐藏。

        optionsFragment = new TrackOptions();
        var trans = Activity.SupportFragmentManager.BeginTransaction();
        trans.Add(trackOptionsContainer.Id, optionsFragment, "Track Options");
        trans.Hide(optionsFragment);
        trans.Commit();

Then, in the parent fragment, when I want to show this child fragment, I simply call to show it and when I want it to go away, I hide it again. 然后,在父片段中,当我想要显示该子片段时,我只是调用以显示它,而当我希望它消失时,我再次将其隐藏。

At first, I noticed that the child was transparent and I could see through it to the parent. 起初,我注意到孩子是透明的,我可以透过父母看到它。 If I then set a background, that problem went away. 如果再设定背景,该问题就消失了。

However, now I noticed that while I am viewing the child and clicking on screen, the parent will still respond to events (click events) for buttons that aren't visible because they are on the parent, which is covered by showing the child. 但是,现在我注意到,当我查看孩子并单击屏幕时,父级仍会响应事件(单击事件),因为按钮在父级上不可见,因此显示了孩子。

I suspect this is because I need to explicitly also hide the parent when I am showing the child. 我怀疑这是因为当我向孩子展示时,我还需要明确隐藏父母。 Is this correct? 这个对吗? If so, here are two follow up questions that I don't understand. 如果是这样,这是我不理解的两个后续问题。 1. I don't want to re-instantiate the parent each time I want to show it. 1.我不想每次都想给父母重新实例化。 I just want the one instance that was created when the app launched. 我只想要应用启动时创建的一个实例。 If I have to explicitly hide it, how do I show it again while using the same instance of the fragment class? 如果必须显式隐藏它,如何在使用片段类的相同实例时再次显示它? 2. I have read so many different options to get an event when a fragment is shown and I have tried most of them (OnHiddenChanged, OnResume, UserVisibleHint) but none of them seem to work well with this child fragment setup. 2.我已经阅读了很多不同的选项,以便在显示片段时获得事件,并且我尝试了其中的大多数选项(OnHiddenChanged,OnResume,UserVisibleHint),但是这些选项似乎都不适合此子片段设置。 What even do I use when my child fragment is shown? 显示我的孩子片段时,我什至还要使用什么?

Thanks! 谢谢!

Mike 麦克风

Just set your fragment as clickable, thus it will not allow clicks to pass through. 只需将您的片段设置为可点击,就不会允许点击通过。 Don't worry, as the background of the fragment is not a clickable background, you will not see any clicks. 不用担心,因为片段的背景不是可点击的背景,所以您不会看到任何点击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当另一个 View 或 Fragment 在它上面时,如何防止 ListView 接收点击? - How do I prevent a ListView from receiving clicks when another View or Fragment is over it? DataGridViewLinkColumn 不响应点击 - DataGridViewLinkColumn does not respond to clicks 当用户使用C#在Unity中单击它们时,我希望两个对象播放它们各自的动画 - I would like two objects to play their separate animations when the user clicks on them in Unity using C# 无法反序列化当前 json object 当我尝试将以下 Json 数据读取到对象时显示消息 - cannot deserialize the current json object Message shows when I try to read the below Json data into Objects WPF如何重用Popup窗口xaml片段以显示多次不同的按钮单击 - WPF How to reuse Popup window xaml fragment to show on multiple different button clicks 当用户在作为 ShowDialog 启动的 window 之外单击时显示消息 - Show a message when user clicks outside a window thats launched as ShowDialog 用户单击列表框项时如何显示按钮? - How to show button when the user clicks a listbox item? TreeView复选框仅响应双击 - TreeView check boxes only respond to double clicks Unity(新)InputSystem 确实响应鼠标点击 - Unity (new) InputSystem does respond to mouse clicks 当用户单击DropDown按钮时,如何不在DateTimePicker中显示日历 - How not to show calendar in the DateTimePicker when user clicks DropDown button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM