티스토리 뷰
방법 1. Gravity 사용하기
아주 직관적인 flag를 사용하여 사용이 간편하고 쉽습니다.
Gravity flag 확인하기
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | AXIS_CLIP | Raw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied. | |||||||||
int | AXIS_PULL_AFTER | Raw bit controlling how the right/bottom edge is placed. | |||||||||
int | AXIS_PULL_BEFORE | Raw bit controlling how the left/top edge is placed. | |||||||||
int | AXIS_SPECIFIED | Raw bit indicating the gravity for an axis has been specified. | |||||||||
int | AXIS_X_SHIFT | Bits defining the horizontal axis. | |||||||||
int | AXIS_Y_SHIFT | Bits defining the vertical axis. | |||||||||
int | BOTTOM | Push object to the bottom of its container, not changing its size. | |||||||||
int | CENTER | Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. | |||||||||
int | CENTER_HORIZONTAL | Place object in the horizontal center of its container, not changing its size. | |||||||||
int | CENTER_VERTICAL | Place object in the vertical center of its container, not changing its size. | |||||||||
int | CLIP_HORIZONTAL | Flag to clip the edges of the object to its container along the horizontal axis. | |||||||||
int | CLIP_VERTICAL | Flag to clip the edges of the object to its container along the vertical axis. | |||||||||
int | DISPLAY_CLIP_HORIZONTAL | Special constant to enable clipping to an overall display along the horizontal dimension. | |||||||||
int | DISPLAY_CLIP_VERTICAL | Special constant to enable clipping to an overall display along the vertical dimension. | |||||||||
int | FILL | Grow the horizontal and vertical size of the object if needed so it completely fills its container. | |||||||||
int | FILL_HORIZONTAL | Grow the horizontal size of the object if needed so it completely fills its container. | |||||||||
int | FILL_VERTICAL | Grow the vertical size of the object if needed so it completely fills its container. | |||||||||
int | HORIZONTAL_GRAVITY_MASK | Binary mask to get the horizontal gravity of a gravity. | |||||||||
int | LEFT | Push object to the left of its container, not changing its size. | |||||||||
int | NO_GRAVITY | Constant indicating that no gravity has been set | |||||||||
int | RIGHT | Push object to the right of its container, not changing its size. | |||||||||
int | TOP | Push object to the top of its container, not changing its size. | |||||||||
int | VERTICAL_GRAVITY_MASK | Binary 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);
'Computer > Android' 카테고리의 다른 글
Android File 입출력 (0) | 2013.12.11 |
---|---|
AlertDialog.Builder 사용 예제 (0) | 2013.11.26 |
안드로이드/Android LayoutInflater 사용 방법 (0) | 2013.11.09 |
Custom Android TabWidget with Badges (0) | 2013.11.09 |
안드로이드/Android Rect Class(클래스) 사용 하기 (0) | 2013.07.25 |
댓글