1.获取状态栏的高度
/**
* 用于获取状态栏的高度。
*
* @return 返回状态栏高度的像素值。
*/
private int getStatusBarHeight() {
if (statusBarHeight == 0) {
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object o = c.newInstance();
Field field = c.getField("status_bar_height");
int x = (Integer) field.get(o);
statusBarHeight = getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
}
return statusBarHeight;
}
2.设置listview的高度,使其无滑动效果
/**
* 根据listitem的数量来listview确定高度
* 使listview无需滑动
* @param listView
*/
private void setListViewHeightBasedOnChildren(ListView listView)
{
ListAdapter listAdapter = (ListAdapter) listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++)
{
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
3.得到设备所有内存
/**
* 得到设备的所有RAM
* @return 返回所有内存大小,单位:kb
*/
private int getAllMemory() {
String filePath = "/proc/meminfo";
int ram = 0;
FileReader fr = null;
BufferedReader localBufferedReader = null;
try {
fr = new FileReader(filePath);
localBufferedReader = new BufferedReader(fr, 8192);
String line = localBufferedReader.readLine();
int a = line.length() - 3;
int b = line.indexOf(' ');
String str = line.substring(b, a);
while (str.substring(0, 1).equals(" ")) {
str = str.substring(1, str.length());
}
ram = Integer.parseInt(str);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fr.close();
localBufferedReader.close();
} catch (Exception e) {