Friday

Set Two Layout Programmatically in Android

Set two different layout in res res/layout folder, set the the these two layout file programmatically in android.

Put these code in onCreate in you activity.


DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

int screen_size = (conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);

if ((metrics.densityDpi == DisplayMetrics.DENSITY_LOW || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH)
&& screen_size == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
setContentView(R.layout.test_hdpi);
} else {
setContentView(R.layout.test);
}

Hopefully you enjoy it. Happpy Coding !

0 comments

Posts a comment

Related Posts  www.prandroid.com...
 
© 2011 Android Programming Tutorails | 2012 Templates
Designed by Blog Thiết Kế
Back to top