안드로이드 개발 질문/답변
(글 수 45,052)
FrameLayout fl = (FrameLayout)findViewById(R.id.quiz_record);
int width = fl.getWidth();
int height = fl.getHeight();
위에 이렇게 하면 둘다 0반환해요...
크기에 맞게 draw하고 싶은데..
너비하고, 높이 값 얻는 방법 좀 부탁드립니다.
2011.06.25 23:31:33
아.. 다른 방식으로 해결했어요 ^^;; 어차피 그리는데서 사용할려고했었는데 내부클래스에서
private class MyView extends View
{
int width;
int height;
public MyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld){
super.onSizeChanged(xNew, yNew, xOld, yOld);
width = xNew;
height = yNew;
}
public void onDraw(Canvas canvas)
{
RectF r = new RectF(10, 10, width-10, height-10);
canvas.drawColor(Color.parseColor("#00dde5ff"));
pnt_roundBox.setColor(Color.parseColor("#33dde5ff"));
canvas.drawRoundRect(r, 30, 30, pnt_roundBox);
}
}
이런식으로 ^^
FrameLayout 은 특성이, 자식 View 들의 사이즈에 맞게 자기를 맞춥니다.
우선 안에있는 View 들 셋팅 모두 마치신후, onLayout 이 호출된 이후에 getWidth(), 또는 getHeight() 호출하면 됩니다.
onLayout 호출된 이후시점 찾기가 어려우시면, 그냥 fl.post(new Runnable() 이런 식으로 post 로 얻어내시면 됩니다.