What I meant to say in my comment earlier was that there are many popular solutions here to get the height and width of any android view.
I have tested this code right now and it is working fine. Try this:
final RelativeLayout topLayout = (RelativeLayout) findViewById(R.id.topRelLayout);
ViewTreeObserver viewTreeObserver = topLayout.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= 16)
topLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
else
topLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int viewWidth = tabs.getWidth();
int viewHeight = tabs.getHeight();
Toast.makeText(HomeScreenActivity.this, "height = " + viewHeight + " width = " + viewWidth , 2000).show();
}
});
}
Where topRelLayout is the id of root layout of your xml file and tabs is the reference to your tab view.
Even following simple code is working fine too.
tabs.post(new Runnable() {
@Override
public void run() {
int w = tabs.getMeasuredWidth();
int h = tabs.getMeasuredHeight();
Toast.makeText(HomeScreenActivity.this, "height = " + h + " width = " + w , 2000).show();
}
});
Using either of the solutions you can get the height/width of any view in any screen size.
EDIT :
After reading your edited question I assume that you need what percentage of the screen has been occupied by Tab widget.
Only solution I know can be implemented is :
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
tabs.post(new Runnable() {
@Override
public void run() {
int h = tabs.getMeasuredHeight();
int screenHeight = 0;
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= 13)
{
Point point = new Point();
display.getSize(point);
screenHeight = point.y;
}
else
screenHeight = display.getHeight();
double tabPart = (((double)h/(double)screenHeight) * 100);
Toast.makeText(HomeScreenActivity.this, "height = " + screenHeight + " tabPart = " + tabPart + " %", 2000).show();
}
});