자체 ViewGroup 속성 + LayoutParams 속성 함께 학습해야 함.
android:orientation="vertical"
수직 배치android:orientation="horizontal"
수평 배치android:gravity="right|bottom"
우측 하단 배치
속성값
- top : 상단 / bottom : 하단
- left : 좌측 / right : 우측
- center_vertical : 수직 중앙 / center_horizontal : 수평 중앙
- center : 정중앙
android:baselineAligned="true"
android:baselineAlignedChildIndex="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:measureWithLargestChild="true"
android:weightSum="10"
기준 View(anchor View)와의 관계에 따라 배치
android:ignoreGravity="@id/view2"
+) 대상 지칭 문법
android:layout_alignParentLeft="true"
android:layout_alignParentRight"true"
android:layout_alignParentTop"true"
android:layout_alignParentBottom"true"
android:layout_centerHorizontal"true"
android:layout_centerVertical"true"
android:layout_centerInparent"true"
android:layout_above="anchor view id"
android:layout_below="anchor view id"
android:layout_alignTop="anchor view id"
android:layout_alignBottom="anchor view id"
android:layout_toLeftOf="anchor view id"
android:layout_toRightOf="anchor view id"
android:layout_alignLeft="anchor view id"
android:layout_alignRight="anchor view id"
android:layout_alignBaseline="anchor view id"
속성을 조합하는 것이 아주 중요함 !
android:visibility="visible"
디폴트값android:visibility="invisible"
영역은 유지android:visibility="gone"
영역도 사라짐android:layout_alignWithParentIfMissing="true"
겹쳐서 배치
android:foregroundGravity="right|bottom"
android:measureAllChildren="true"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Change Image"
android:onClick="onButton1Clicked"/>
//Click 이벤트 실행 시 호출되는 event handling 함수명
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background"
android:visibility="invisible"/>
<ImageView
android:id="@+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background"
android:visibility="visible"/>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
ImageView iv01;
ImageView iv02;
int ImageIdx = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv01 = (ImageView) findViewById(R.id.imageView01);
iv02 = (ImageView) findViewById(R.id.imageView02);
}
public void onButton1Clicked(View v) {
changeImage();
}
private void changeImage() {
`if (imageIdx == 0) {
iv01.setVisibility(View.VISIBLE);
iv02.setVisibility(View.INVISIBLE);
imageIdx = 1;
} else {
iv01.setVisibility(View.INVISIBLE);
iv02.setVisibility(View.VISIBLE);
imageIdx = 0;
표 형태로 배치
android:collapseColumns="0,2"
android:shrinkColumns="1"
android:stretchColumns="1"
android:layout_column="1"
android:layout_span="2"
android:orientation="horizontal"
android:rowCount="100"
android:columnCount="2"
android:alignmentMode="alignMargins"
너비 혹은 높이가 가장 큰 View의 여백(margin)을 포함해서 정렬X (default값)
android:alignmentMode="alignBounds"
margin 포함해서 정렬O
android:columnOrderPreserved="true"
android:columnOrderPreserved="false"
android:useDafaultMargins="true"
android:layout_row="1"
android:layout_column="1"
android:layout_columnSpan="2"
<Space android:layout_gravity="fill_horizontal"/>
글이 읽기가 좋네요!