2012-05-31 4 views
0

보이지 않는 레이아웃의 새로 고침/페인트를 강제하는 방법을 아는 사람이 있습니까?보이지 않는 Android 레이아웃의 새로 고침

저는 레이아웃 중 하나가 순간에 보이지 않을 수도 있지만 복잡한 비트 맵으로 변환하여 크기가 작고 확장 가능한 가시 레이아웃으로 표시하려고합니다.

레이아웃을 비트 맵에 쉽게 복사 한 다음 해당 비트 맵을 더 작은 보이는 윈도우의 ImageView에 배치 할 수 있습니다. 그러나 우리가 다루고있는 문제는 보이지 않는 창에서보기가 변경되거나 제거되거나 추가되면 안드로이드는 실제로 그 그림을 그리지 않는다는 것입니다. 따라서 작은 보이는 레이아웃에 배치 된 가져온 비트 맵은 부실하고 정적입니다.

보이지 않는 레이아웃을 강제로 다시 그리는 방법이 있습니까?

답변

0

LinearLayout을 확장하고 onMeasure 함수를 덮어 쓰면 전체 레이아웃 크기 (화면 + 스크린 외부)를 반환하십시오. 이 코드는 시작하기 수

아닌 눈에 보이는 레이아웃으로이 레이아웃을 사용합니다 ..

public class YourLayout extends LinearLayout { 
    private Context myContext; 

    public YourLayout(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ 
    /* 
    * Magic!!! Android doesn't draw parts of layout which is offscreen. Since YourLinear layout has some offscreen part 
    * its offscreen portions didn't get drawn. 
    * This onMeasure function determines how much pixel of a layout need to be drawn. 
    * widthMeasureSpec  -> Width of YourLayout onscreen 
    * heightMeasureSpec  -> height of YourLayout on screen 
    * your_view_offscreen_width -> width of offscreen part 
    * your_view_offscreen_height-> height of offscreen part 
    * So heightMeasureSpec + your_view_offscreen_height draws complete height of YourLayout whether it is onscreen or offscreen. 
    * So widthMeasureSpec + your_view_offscreen_width draws complete width of YourLayout whether it is onscreen or offscreen 
    */ 
     super.onMeasure(widthMeasureSpec + your_view_offscreen_width, heightMeasureSpec + your_view_offscreen_height); 
    } 
} 

지금 당신이 아닌 눈에 보이는 레이아웃으로이 레이아웃을 사용할 수 있습니다 ... 즉, 당신이 할 수있는 당신에게 레이아웃 XML을 사용하는 경우 이런 식으로 사용하십시오

<com.your.package.YourLayout layout_width="fill_parent" layout_height="fill_parent" 
    ...... 
> 
+0

감사합니다. Krishnabhadra! 그러나 그것은 제가 얻고있는 것이 아닙니다. 내가 "보이지 않는다"고 말할 때 나는 오프 스크린을 의미하지 않는다. 즉, 레이아웃이 다른 레이아웃 (즉, 표시된 레이아웃을 변경하기 위해 setContentView())에 의해 대체되었습니다. 나는 안드로이드 멍청 아 그래서 어쩌면 내가 잘못된 용어를 사용하고있다. – Batdude