Rotating Views (but not Layouts) on screen orientation change

岁酱吖の 提交于 2019-12-02 02:44:52

Create res->layout->layout-land and put your xml file for landscape mode

Your layout file in layout folder is only for portrait mode Now if you need landscape then create layout-land folder.

GAMA

It can be done it two ways:

1.) Either you define a new xml file in layout-land folder.

2.) Use android:configChanges="orientation" in your activity tag inside manifest.xml

Then in your activity class:

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

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        ChangeToLandscape();
    } else {
        ChangeToPortrait();
    }
}

LayoutParams lp;
public void ChangeToLandscape() {
    lp = new LayoutParams(new ViewGroup.MarginLayoutParams(
            LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
    textView1.setLayoutParams(lp);
    lp.setMargins(0, 0, 0, 0); // Whatever you want
    // Similar for other views
}

//Similarly, implement `ChangeToPortrait()`

Hope it helps !!!

You'll have to change the layout parameters.

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