简体   繁体   中英

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

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?

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.

为横向模式制作一个额外的布局xml文件,并将其放入文件夹“ layout-land”

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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