Analysis on Layout for Android

current situation

If you don’t konw the layout of android phone screen, you couldn’t design a app you want. Where you can place controller and where you can place notification. These are you must know before you coding.

Analysis of Layout

Desc on Layout

The action bar is a dedicated piece of real estate at the top of each screen that is generally persistent throughout the app.

It provides several key functions:

  • Makes important actions prominent and accessible in a predictable way (such as New or Search).
  • Supports consistent navigation and view switching within apps.
  • Reduces clutter by providing an action overflow for rarely used actions.
  • Provides a dedicated space for giving your app an identity.

If you’re new to writing Android apps, note that the action bar is one of the most important design elements you can implement. Following the guidelines described here will go a long way toward making your app’s interface consistent with the core Android apps

Use of Every Bars

status bar height

1
2
3
Rect frame = new Rect();    
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;

title bar height

1
2
3
int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();   
//statusBarHeight is the height of status bar
int titleBarHeight = contentTop - statusBarHeight

screen height

1
2
3
4
5
6
7
8
9
10
11
WindowManager windowManager = getWindowManager();   
Display display = windowManager.getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();

//or

DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);//this指当前activity
screenWidth =dm.widthPixels;
screenHeight =dm.heightPixels;

combine codes above as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 // status bar height
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}

// action bar height
int actionBarHeight = 0;
final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
new int[] { android.R.attr.actionBarSize }
);
actionBarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();

// navigation bar height
int navigationBarHeight = 0;
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
navigationBarHeight = resources.getDimensionPixelSize(resourceId);
}