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.
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:
write fragment_main.xml in layout folder (1 column layout)
write fragment_main_land.xml in layout folder (2 column layout)
create layouts.xml file in values-land folder code lines
<resources> <item name="layout_main" type="layout">@layout/fragment_main</item> </resources>
create layouts.xml file in values-land folder code lines
<resources> <item name="layout_main" type="layout">@layout/fragment_main_land</item> </resources>
on oncreateview method of mainfragment, inflater.inflate(r.layout.layout_main, null);
Comments
Post a Comment