在我的应用程序中,我需要知道主要活动容器的大小。我写了以下代码:
Button btnActionMenu = (Button) findViewById(R.id.actionbar_menu);
btnActionMenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
RelativeLayout rlContainer = (RelativeLayout) findViewById(R.id.inner_content);
Bitmap bitmap = Bitmap.createBitmap(rlContainer.getLayoutParams().width, rlContainer.getLayoutParams().height, Config.ARGB_8888);//
Canvas canvas = new Canvas(bitmap);
rlContainer.draw(canvas);
SlideoutHelper.setBitmap(bitmap, width);
startActivity(new Intent(Home.this, MenuActivity.class));
overridePendingTransition(0, 0);
}
});
rlContainer
是活动的根容器。当我运行并单击按钮时,应用程序崩溃并且 Logcat 说“应用程序空指针异常”并指向行
Bitmap bitmap = Bitmap.createBitmap(rlContainer.getLayoutParams().width, rlContainer.getLayoutParams().height, Config.ARGB_8888);
任何建议将不胜感激。谢谢