티스토리 뷰

  • 테이블 레이아웃이란?
격자 형태로 배치하는것이다.
  • <TableRow>
칼럼의 수가 증가된다. 표형식으로 오른쪽으로 생겨난다.
공간을 할당 받는다. TableLayout 안에 넣어준다.
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
 
    </TableRow>
</TableLayout>
cs
tableLayout은 높이 값이 없다.
tablerow는 layout_width , layout_height의 속성을 match_parent로 바꾼다고 해도 별 상관이 없다. 높이가 없으므로.

  • 버튼을 3개씩 2그룹을 추가해준다. TableRow 아래에
첫번째 줄 3개
두번째 줄 3개로 추가해준다.
버튼들이 추가하면 오른쪽에 남는공간 없이 세개버튼이 공간을 알맞게 할당받고 싶으면
Text.xml 에서 

  • android:stretchColums 속성
TableRow 안에 추가된것들을 칼럼이라고 생각하면된다. 각각의 칼럼들을 인덱스 값으로 지정하여 어느 공간까지 stretch 어디까지 채울건지를 정해주는 속성이다.
android:stretchColumns="0,1,2"


결국 TableLayout에 있는 칼럼들 0,1,2을 차지하고 있는것들이 각각의 자리를 차지하게되어 빈 공백없이 깔끔하게 채워진다.
  • 다른형태로 만들고 싶을경우?
app-res-layout-> new ResourceFile -> activity_menu.xml 생성

Root element를 TableLayout으로 만들겠다(최상위를 만들겠다) 라는 뜻이라서 이렇게 수정을 해준다.
이렇게 xml 파일을 만들게 되면 TableLayout이 최상위 레이아웃이 된것을 확인 할 수 있다.





  • 새로운 XML 파일에 새로운 뷰들을 추가 해보자+
EditText = 입력 상자를 나타낸다.
android:layout_span="3" 얼마나 차지 하게 하겠는가 라는뜻이다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="0.1.2">
 
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="이름 : "/>
 
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"/>
 
    </TableRow>
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="아니오"
            android:layout_column="1"/> // 칼럼을 두번째 칼럼에 넣고 싶을 때 '1'값
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="예"
            android:layout_column="2"
            />
 
    </TableRow>
 
 
</TableLa
 
 
yout>
cs

  • 안드로이드에서는 스크롤뷰를 어떻게 만들까?
프로젝트를 닫고 Example_ScrollView 를 생성 해보자.

스크롤뷰는  위젯의 내용이 화면 영역을 벗어나면 스크롤 표시가 자동으로 보인다.
스크롤뷰를 이용해 다른뷰를 감싸주기만 하면 끝!!! 쉽습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
 
    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button"
       />
 
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
 
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
 
            <TextView
                android:textSize="50dp"
                android:text="안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n안녕하세요\n"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textView2" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>
cs

한글 깨짐현상이 조금 보이지만 에뮬레이터에서는 정상적으로 나오네요.

저렇게 화면에서보면 화면을 초과하였을 경우 스크롤바가 보이는것을 알수있습니다.

스크롤뷰를 추가하게되면 자동으로 최상위 레이아웃이 스크롤뷰 안으로 들어갑니다.




공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
글 보관함