티스토리 뷰

방법 1. Gravity 사용하기


아주 직관적인 flag를 사용하여 사용이 간편하고 쉽습니다.


Gravity flag 확인하기


 

Constants

intAXIS_CLIPRaw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied.
intAXIS_PULL_AFTERRaw bit controlling how the right/bottom edge is placed.
intAXIS_PULL_BEFORERaw bit controlling how the left/top edge is placed.
intAXIS_SPECIFIEDRaw bit indicating the gravity for an axis has been specified.
intAXIS_X_SHIFTBits defining the horizontal axis.
intAXIS_Y_SHIFTBits defining the vertical axis.
intBOTTOMPush object to the bottom of its container, not changing its size.
intCENTERPlace the object in the center of its container in both the vertical and horizontal axis, not changing its size.
intCENTER_HORIZONTALPlace object in the horizontal center of its container, not changing its size.
intCENTER_VERTICALPlace object in the vertical center of its container, not changing its size.
intCLIP_HORIZONTALFlag to clip the edges of the object to its container along the horizontal axis.
intCLIP_VERTICALFlag to clip the edges of the object to its container along the vertical axis.
intDISPLAY_CLIP_HORIZONTALSpecial constant to enable clipping to an overall display along the horizontal dimension.
intDISPLAY_CLIP_VERTICALSpecial constant to enable clipping to an overall display along the vertical dimension.
intFILLGrow the horizontal and vertical size of the object if needed so it completely fills its container.
intFILL_HORIZONTALGrow the horizontal size of the object if needed so it completely fills its container.
intFILL_VERTICALGrow the vertical size of the object if needed so it completely fills its container.
intHORIZONTAL_GRAVITY_MASKBinary mask to get the horizontal gravity of a gravity.
intLEFTPush object to the left of its container, not changing its size.
intNO_GRAVITYConstant indicating that no gravity has been set
intRIGHTPush object to the right of its container, not changing its size.
intTOPPush object to the top of its container, not changing its size.
intVERTICAL_GRAVITY_MASKBinary mask to get the vertical gravity of a gravity.



방법 2. margin 사용하기

자식뷰들에게 margin을 적용하기 위해서는 일단 부모뷰FramLayout의 top이나 bottom에 붙여야적용이 됩니다.

 

<!-- .xml 리소스 파일의 속성으로 사용하기 -->

<FrameLayout ... >

    <TextView ... android:layout_gravity="top" android:layout_marginLeft="44dp" />

</FrameLayout>

 

// .java 소스 파일의 메쏘드로 사용하기

Button btn = new Button(this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CO

        NTENT, LayoutParams.WRAP_CONTENT);

params.gravity = Gravity.TOP;
params.setMargins (int left, int top, int right, int bottom);
btn.setLayoutParams(params);

댓글

파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음



Total
Today
Yesterday
최근에 달린 댓글