java - Change fragment layout portrait to landscape -


i work fragment problem : when change orientation, if had 2 columns in scrollview still in screen portrait, or if had 1 column in portrait mode when pass landscape had 1 column.

i had 3 layout same name number of columns change, put in folder layout, layout-land , layout-port.

what need when passe portrait landscape passe 2 columns one, , vice versa.

enter image description here

enter image description here

enter image description here

you can't put in folder layout, layout-land , layout-port make work. there 3 more steps need do: 1. create layout.xml file in values folder 2. put xml layout 2 column in layout-land , layout 1 column in layout-port 3. in oncreateview() in fragment, inflate layout's name in layout.xml file instead current layout.

for more details, i'll show code: you're gonna write mainfragment , create fragment_main.xml layout. need is:

  1. write fragment_main.xml in layout folder (1 column layout)

  2. write fragment_main_land.xml in layout folder (2 column layout)

  3. create layouts.xml file in values-land folder code lines <resources> <item name="layout_main" type="layout">@layout/fragment_main</item> </resources>

  4. create layouts.xml file in values-land folder code lines

    <resources> <item name="layout_main" type="layout">@layout/fragment_main_land</item> </resources>

  5. on oncreateview method of mainfragment, inflater.inflate(r.layout.layout_main, null);


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -