First, I must say that i am beginner. But have made an application, that works on my Nexus 7 tablet. But i want to make it to work in all devices. Yes, I know, that question has been there before. But I want your opinion, will it work if etc...
public void setLayout()
{
DisplayMetrics dm = new DisplayMetrics(); //avoid this it just gets screen size.
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels;
int height=dm.heightPixels;
int dens=dm.densityDpi;
double wi=(double)width/(double)dens;
double hi=(double)height/(double)dens;
double x = Math.pow(wi,2);
double y = Math.pow(hi,2);
double ss = Math.sqrt(x+y);
if(ss <7) //n7 If screen size is nexus 7, application will set nexus7 layout
{
setContentView(R.layout.screen7);
}
else
{
setContentView(R.layour.default); //user is not using nexus 7 so we will set default layout
}
But i need to run this method in every activity, that need to set layout. Like in MainActivity, instead of using setContentView(R.layout.activity_main);
I want to use setLayout(); //so method checks what screen size user is using so we can show the best layout available.
I hope you understand what i want to make ;) Thank you :) Please let me know, if you want LogCat error.