简体   繁体   English

不同的风景和肖像活动

[英]Different activities for landscape and portrait

I have no idea of this is actually possible, but i want the device to have different activities for landscape and portrait. 我不知道这实际上是可能的,但是我希望设备对风景和肖像进行不同的活动。 I have a listview, and of all the items in my listview i have the coordinates. 我有一个列表视图,并且列表视图中的所有项目都有坐标。 So i thought, it would be nice if you put your device in landscape, and show a mapview with icons placed on the locations of the items. 所以我想,如果您将设备放置在风景中,并在项目位置上放置带有图标的mapview,那就太好了。

I know you can create different layouts for different orientations, but only creating an mapview and using that as landscape layout wont do the trick i guess. 我知道您可以为不同的方向创建不同的布局,但是我只能猜出只有创建一个mapview并将其用作景观布局的窍门。 Is there something possible in an equivalent way for activities? 是否有可能以等效的方式进行活动? I couldn't find it, so probably not. 我找不到,所以可能找不到。

Else i think this might work: I thought myself of a switch in the activity: on portrait --> do this and load this layout, on landscape --> do that and use the other layout. 否则,我认为这可能会起作用:我认为自己在活动中进行了切换:在肖像上->执行此操作并加载此布局,在风景上->执行此操作并使用其他布局。 But this would only work once if put in the oncreate. 但是,如果将其放在oncreate中,则只能使用一次。 But than the orientationlistener would do the trick. 但是比定向监听器更能解决问题。 Anyone knows of this is possible? 有人知道这可能吗?

There is a method in activity lifecycle 活动生命周期中有一种方法

public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);                
            // Check the Orientation of Device
            // Start Other Activity
    ...
    ...
    ...

}

you can use this method to change the activity if the device orientation changes. 如果设备方向发生变化,则可以使用此方法来更改活动。

IMHO we can't use 2 different activities here, but there is a way, 恕我直言,我们在这里不能使用2种不同的活动,但是有一种方法,

please check out how to detect orientation dynamically here, check-orientation-on-android-phone 请在此处查看如何动态检测方向, 在Android手机上检查方向

once you are through this, you can include code for landscape mode here in the same activity. 完成此操作后,您可以在同一活动中在此处包含横向模式的代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM