[안드로이드] setVisibility 사용하기

  안드로이드에서 UI 작업을 하다보면 setVisibility 라는 함수를 자주 사용하게 됩니다. 이 함수는 int 형 인자를 받게 되는데, 저도 처음에는 0~100까지 숫자를 넣어야 되는줄 알았는데, 그게 아니라 아래와 같은 상수를 넣어서 사용을 해야 합니다.
.



 private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE};

    /**
     * This view is visible.  Use with {@link #setVisibility}.
     */
    public static final int VISIBLE = 0x00000000;


    /**
     * This view is invisible, but it still takes up space for layout purposes.
     * Use with {@link #setVisibility}.
     */
    public static final int INVISIBLE = 0x00000004;


    /**
     * This view is invisible, and it doesn’t take any space for layout
     * purposes. Use with {@link #setVisibility}.
     */
    public static final int GONE = 0x00000008;


.
 
 View Class에 있는 상수기 때문에 View.INVISIBLE 과 같이 사용하면 됩니다. 각 상수를 보면 VISIBLE, INVISIBLE는 보이게, 안보이게 처리하는 것이고, GONE은 없는 것과 같이 처리를 하는 것입니다. 어떠한 View를 숨길 때 해당 공간이 비어서 보이게 하고 싶다면 INVISIBLE를 사용하고, 해당 공간을 다른 View가 점유할 수 있게 하려면 GONE를 사용하면 될 것입니다. 반대로다시 보이게 하려면 VISIBLE를 사용하면 됩니다.



답글 남기기

이메일 주소는 공개되지 않습니다.