Gabriel
We have some ways available to perform this manipulation of layouts on different devices.
Drawable
Offers the following sizes
- ldpi (low) ~120dpi
- mdpi (medium) ~160dpi
- hdpi (high) ~240dpi
- xhdpi (extra-high) ~320dpi
- xxhdpi (extra-extra-high) ~480dpi
- xxxhdpi(extra-extra-extra-high) ~640dpi
With this each file inside these folders will treat a different screen size.
Dimens.xml
This xml that should be in res/values/dimens.xml
enables us to perform customizations such as:
Note: Briefly SP for typography and DP for everything else.
Fragments
We have since version 3.0 HoneyComb
the use of Fragments
for the creation and dynamic layouts, thinking of the various screen sizes that exist currently(Tablets and mobile phones with different screens).
Note: You can use the support library for lower versions, careful at import time should be:
android.support.v4.app.Fragment
The image above demonstrates the Fragments in action, for example on the tablets the screen can fully display its layout, when you click on any item in the list, will be loaded beside without needing to change the iteration of the screens, in the figure on the right we have the use of Fragments in devices with smaller screens where we have Fragment A which when clicked directs to the Fragment B, C or how many are needed to mount your screen.
Example to inflate your Fragment taken from documentation
public static class ExampleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.example_fragment, container, false);
}
}
To inflate the Fragments we need to override the method onCreateView
and return the view inflated, but nothing prevents you from using also the method OnCreate
just need to stay on top of Fragment’s life cycle.
Life cycle of Fragments
onAttach(Activity) - This method is called right after Fragment is associated with Activity
onCreate() - This method is only called once and when Fragment is being created. He will receive the Bundle that was saved during the onSaveInstanceState(state method)
onCreateView(Inflater, viewgroup,) - In this method, Fragment needs to create the view that will be inserted in the Activity layout>
onActivityCreated(Bundle) - This method is called right after Activity onCreate() has been finalized.
onDestroyView() - This method is called when the Fragment view has been removed and no longer belongs to Fragment.
onDestroy() - Called to indicate that Fragment is no longer being used.
Ondetach() - Opposite of the onAttach(Activity).
How are you setting the size of views? Post an example of a layout.
– ramaral
Give a study in Fragments ;) http://blog.caelum.com.br/layouts-simples-com-android-fragments/
– Alysson Chicó
@Gabriel, any way out?
– Wellington Avelino