그림 출처는 한빛 아카데미에서 나온 Android Studio를 활용한 안드로이드 프로그래밍



뷰는 화면에 나오는 모든것들이 상속 받고 있는 클래스다.


버튼이나 텍스트같은 위젯은 물론이고 이것들을 정렬하는 레이아웃도 뷰를 상속하고 있다.




아래는 자주쓴다는 뷰의 속성들을 가지고 만든 예제 이다.


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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!--xml에서 주석은 이렇게 쓴다 하지만 내용 중간에(전문용어로는 애트리뷰트라고 하는 듯)쓰면 빨간줄이 쳐진다-->
<!--따라서 설명하고 싶은 부분은 괄호를 처서 설명할거임 '()' -->
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" (정렬방향을 정함 (기본은 가로방향))
    android:paddingTop="50dp" (안쪽에 위쪽으로 간격을  (위나 아래로 따로 주고 싶다면 뒤에 paddingTop paddingLeft등을 사용하면 됨))
    tools:context="com.stuban.test222.MainActivity">
 
 
    <TextView
        android:id="@+id/textview" (java코드에서 위젯을 찾기위한 id @+id/textView는 R파일의 id에 textView를 추가한다는 뜻)
        
        (위젯의 크기 match_parent는 부모의 사이즈에 맞추는 거고 wrap_content는 내용물의 크기에 맞추는 것)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        
        android:background="#FF0000" (배경색)
        
        android:text="test"
        />
 
    <!--visibility-->
 
    <TextView
        android:visibility="invisible" (안보임)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="invisible"
        />
 
    <TextView
        android:visibility="visible" (보임 (기본))
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="visible"
        />
 
    <TextView
        android:visibility="gone" (그냥 없는 취급)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="gone"
        />
 
    <!--enabled,clickable-->
 
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        />
 
    <Button
        android:enabled="false"(버튼 사용 못함)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="!enabled"
        />
 
    <Button
        android:clickable="false" (터치 무시)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="!clickable"
        />
 
    <!--rotation-->
 
    <Button
        android:layout_marginTop="100dp"(바깠쪽에 간격을  (위나 아래로 따로 주고 싶다면 뒤에 marginTop marginLeft등을 사용하면 됨))
        android:rotation="44" (회전)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
 
</LinearLayout>
cs



결과 



참고 : https://developer.android.com/reference/android/view/View.html

블로그 이미지

stuban

ㅇ.ㅇ

,