Programming/Android
안드로이드 앱 위젯 셀 크기 구하기 (Android determine the actual pixel size of appwidget)
후유증
2014. 8. 27. 10:45
Display display;
display = ((WindowManager)
context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
// cell size of a widget in portrait mode
int xCellSize = 80;
int yCellSize = 100;
if (metrics.widthPixels > metrics.heightPixels)
{
// this means we're in landscape mode, so the cell sizes are adjusted
xCellSize = 106;
yCellSize = 74;
}
int xWidgetSize = 4;
int yWidgetSize = 1;
Log.v("debug",
String.format("your %d x %d appwidget is %d x %d physical pixels.",
xWidgetSize, yWidgetSize,
(int)(xCellSize * xWidgetSize * metrics.density),
(int)(yCellSize * yWidgetSize * metrics.density)));각 셀의 실제 코드를 구하는 예제