This is a simple tutorial to show how to create a FLEXIBLE UI for both Phone and Tablets in Android.
In the figure below you can see the result after running this tutorial.
Tablet in LANDSCAPE MODE
TABLET IN PORTRAIT MODE
TABLET IN PORTRAIT MODE – AFTER CLICKING THE LIST.
PHONE IN PORTRAIT MODE
PHONE IN LANDSCAPE MODE.
This can be achieved through Fragments.
This tutorial will have two parts.
1. In the first part I will show you how to use Fragments from API 11 (Honeycomb) and greater.
2. In the second I will show how to change it to adapt to lower versions from 1.6(Donut) using Google’s supporting Library.
I have already covered the first tutorial here..
Please check it before continue reading this post, because there are only small changes in the first post to make it compatible with the older version of Android.
These are the main changes you have to make.
1. Change all Activity to FragmentActivity and change the import statements like below
2. Change the imports of Fragment from
3. Now in the DetailsActivity.java change this line
4. match_parent is not supported in old versions so change all “match_parent” in all layouts to “fill_parent”
5. Optionally You can change the min-sdkversion in Manifest to 5.
Now you have successfully adapted Fragments to the Older version of Android.