«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

올해는 머신러닝이다.

[팁]원하는 view 사이즈 알아내기 본문

Android/Tip&Tech

[팁]원하는 view 사이즈 알아내기

행복한 수지아빠 2012. 9. 28. 15:21

public int measureCellWidth( Context context, View cell )
{

   
// We need a fake parent
   
FrameLayout buffer = new FrameLayout( context );
    android
.widget.AbsListView.LayoutParams layoutParams = new  android.widget.AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    buffer
.addView( cell, layoutParams);

    cell
.forceLayout();
    cell
.measure(1000, 1000);

   
int width = cell.getMeasuredWidth();

    buffer
.removeAllViews();

   
return width;
}