多个片段和活动交互设计多个、片段

2023-09-04 05:01:25 作者:就连孤独都嘲笑我懦弱

你好,我有三个活动,他们的相应片段 A B ç。片段 A 是一个静态的片段中的其他片段是动态的。

活动 A 已经实施监听片段 A ,这是用于装载片段 B 横向或移动到新的屏幕在单一窗口。

当某个按钮pssed在片段$ P $我要的是 B 它调用了片段 C ,我希望它通过片段被替换 C 横向(片段 A 将仍然是present)或者打开一个新的屏幕在单窗格模式。我有这个简单的code在b活动的onCreate 方法:

 如果(getResources()。getConfiguration()。方向==
            Configuration.ORIENTATION_LANDSCAPE){
        完();
        返回;
    }
 

我试图避免片段片段通信,因为它是令人难以接受的。因此,这是否意味着我必须实现监听片段 B 在这两个活动 A B ,我猜测,当横向活动 A 将装载片段 C 和肖像, B 接管?有没有更好的办法?我以为只是实施活动听者 B ,并传递给活动 A 时,以横向的,但我认为它会已完成之前,甚至有传因上述code。有什么想法吗?

解决方案   

...这是否意味着我实现监听器在这两个B片段   活动A和B,我猜测,在横向时   活动A将加载C片段和肖像,B接管或   有没有更好的办法?我以为只是实施b活动的听众和   传递到活动一个横向的时候,但我认为这将有   过完之前,甚至有传因上述code。

您无法实现监听器只是在 B 的活动,因为 A 的活动必须能够以显示景观片段 C 。如果你担心code复制,那么你可以实现为您实现回调,显示片段 C 键,让你的两个活动的基地活动从基类扩展

当你没有张贴你如何管理这些片段任何真正的code,请记住,如果你是在纵向(在 B 活动展示片段 B ),并点击(或不管你做什么)你替换 C中的片段这不会是进行到活动 A 如果您切换方向为横向。

从一个活动来总结一下交互设计的心路历程 UE 原创 自译教程 zhongyong 设计文章 教程分享

Good day, I have three activities with their corresponding fragments A, B and C. Fragment A is a static fragment the others fragments are dynamic.

Activity A is already implementing a listener for fragment A, which is used to load fragment B in landscape orientation or move to new screen in single pane.

What i want is when a certain button is pressed in fragment B which calls up fragment C, I want it to be replaced by fragment C in landscape orientation(fragment A will still be present) or bring up a new screen in single pane mode. I have this simple code in the activity B onCreate method:

if (getResources().getConfiguration().orientation == 
            Configuration.ORIENTATION_LANDSCAPE) {
        finish();
        return;
    }

I am trying to avoid fragment to fragment communication since it is frowned at. So does this mean I have to implement listeners for fragment B in both activity A and B, am guessing that when in landscape orientation activity A would load up fragment C and in portrait, B takes over? Is there a better way?. I thought of only implementing the listener in activity B and passing to activity A when in landscape orientation but I think it would have been finished before it even got to pass due to the above code. Any thoughts?

解决方案

...so does that mean i implement listener for fragment B in both Activity A and B, am guessing that when in Landscape Orientation Activity A would load up Fragment C and in portrait, B takes over or is there a better way? I thought of only implementing the listener in Activity B and passing to Activity A when in Landscape Orientation but i think it would have been finished before it even got to pass due to the above code.

You can't implement the listener just in the B activity because the A activity has to be able to show the fragment C in landscape. If you are worrying about code duplication then you could implement a base activity for which you implement the callback to show fragment C and make your two activities extend from that base class.

As you didn't post any real code on how you manage those fragments, keep in mind that if you are in the portrait orientation(in the B activity showing fragment B) and by clicking(or whatever you do) you replace the fragment with C this will not be carried to activity A if you switch orientation to landscape.