You have to use different layout folders for tablet and phone.
Default folder is res/layout.
For tablet just create a new folder as res/layout-large, and place tablet mode layout there. Remember these layout xml files need to have the same name. Android system will now look for layout-large folder layouts when application is run under large screens.
You have official documentation about supporting multiple screen sizes (more specifically) here.
<<<<<---------- EDIT : ---------->>>>>
Use under activity to control code under different screen size:
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
String toastMsg;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_LARGE:
toastMsg = "Large screen";
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
toastMsg = "Normal screen";
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
toastMsg = "Small screen";
break;
default:
toastMsg = "Screen size is neither large, normal or small";
}