I would like to know how to make my app support different screen sizes and densities, including tablets, regarding the layout. I've found different answers on SO, but I can't find one that explains this issue the best.
I've already included this in my Manifest:
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
According to this answer, I should create multiple layout folders such as small, large, xlarge.
According to documentation I should create multiple layouts and use size qualifiers such as sw<N>dp
.
Which would be the best solution if my app needs to support both phones and tablts?
Additional question: In connection with the abovementioned question, I have a recycler view with list of items. If the screen is portrait then there's a list, if the screen is landscape, then there's grid.
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
LinearLayoutManager manager = new LinearLayoutManager(getContext());
mBinder.rvHistoryList.setLayoutManager(manager);
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
GridLayoutManager manager = new GridLayoutManager(getContext(), 2);
mBinder.rvHistoryList.setLayoutManager(manager);
}
But, if the app is used on a tablet in portrait mode I would like the items to be in a grid ordered by 2 in a row, if the app is used on a tablet in landscape mode I would like the items to be in a grid ordered by 4 in a row. How can I achieve this?