How to start a new activity when screen orientation changes? Android

为君一笑 提交于 2019-12-12 03:22:02

问题


I am writing an application which in portrait view has a gallery at the top and when you click a picture it will inflate and fill the entire screen.

This works however in landscape mode the gallery covers up most of the picture and it in general looks crappy.

I made a GridView for landscape mode. The problem I am having now is to change it from the gallery activity to the Gridview activity when the orientation changes. Any ideas?


回答1:


Add this to your Activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    startActivity(newActivity)
}

Note that this is a bad idea. Actually, it's a really bad idea. A much better alternative would be to either force one orientation or to create a layout that looks great on both orientations.




回答2:


The right way to do it is to define two layouts, one in layout-port and one in layou-land directories. That is, you will have the following two layouts: res/layout-port/main.xml and res/layout-land/main.xml.

In your software you simply write secContentView(R.layout.main); and android will take care of applying the right layout upon device rotation.




回答3:


Make an extra layout xml file for landscape mode and put it into the folder "layout-land"



来源:https://stackoverflow.com/questions/10157643/how-to-start-a-new-activity-when-screen-orientation-changes-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!