728x90

이번시간에는 View에대해서 짤막하게 소개할까 한다.
사실 View는 원래라면 짤막하게 소개할수 없다. 양이 매우 방대하게 때문.
안드로이드 프로그래밍을 하는데 근간이 되므로 매우 중요하며 새버전이 올라올때마다 View가 추가된다.
그래서 이번 블로그에서는 View에대해서 모든걸 담는건 사실상 불가능 하고,
View가 무엇인지, 자주쓰는건 어떤게 있는지에 대해서 간략히 포스팅 하겠다.


View - 위젯 기반 프로그래밍


GUI프로그래밍에서 현재 자주쓰이는 개념은 위젯이라는 개념이다.

위젯이 뭔고 하면 정말 별거 없이 하나하나 부품이라고 생각하면 된다.

GUI의 요소들이라고 보면되는데 위젯을 각각 GUI별로 완전다른이름으로 부른다.

예를들어 Swing에서는 컴포넌트라고 부르면 SWT에서는 컴포짓이라고 부르고 웹페이지에서는 엘레멘츠라고 부른다.

그러나 부르는 명칭이 어떻던 이런걸 위젯이라는 개념이라고 생각하면 된다.


안드로이드도 이들과 다르지 않다. 대신 View라는 완전 새로운 이름으로 불리울 뿐.

View는 액티비티에 종속되는데(정확히 말하면 액티비티는 아니지만) 액티비티에서 그 목록을 확인할 수 있다.

한번 View목록을 보자.



먼저 layout의 activity_main을 보자.



그러면 다음과 같이 화면이 나온다. 현재 아무것도 손대지 않은 fure한 그상태 그대로의 화면이다.

그런데 왼쪽을 보자. palette가 있다. 여기에 있는 모든 것들이 바로 view이다.

view는 또 여러 하위 분류로 나뉘는데 가장 자주쓰는 view들은 widgets이란 이름으로 정리되어있다.

그리고 여러분들도 처음에 프로그래밍시에는 widgets란에 있는 view들을 위주로 사용하게 될것이다.

여러분이 화면에 보고있는 Hello World!의 글자도 바로 view이다. 이 view는 TextView이다.


view를 한번 추가해보자.

그런데 view를 추가하기 이전에 layout을 한번 수정하자. 왜냐하면 현재 layout은 초심자가 사용하기엔 불편하다.

그러므로 layout을 변경해 줄건데 아래와 같이 행동하자.



액티비티를 선택하면 현재 Desgin모드로 되어있는데 이를 Text모드로 바꿔주자.



그러면 여러분은 액티비티의 코드를 볼 수 있다. 여기서 android.suport.constraint.ConstraintLayout을 LinearLayout으로 바꿔준다.



그러면 이제 글이 새로배치가된다.

여기서 view를 추가하는건 간단하다.



정말쉽게도 드래그하면 끝이다. 물론 코드로도 쓸수 있다. 다시 Text를 눌러보자.


<?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"
tools:context="com.example.jiharu.myapplication.MainActivity">

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CheckBox" />

<CheckedTextView
android:id="@+id/checkedTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CheckedTextView" />

<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>


이로써 여러분들은 View를 화면에 출력할수 있게 되었다.

그러나 문제는 아직 View는 껍데기에 아무 기능이 없다는것이다.

우리는 이 View에 생명을 불어넣어 줄건데 그 작업은 다음강의에서 확인하도록하자.


'Programming > Java-Android' 카테고리의 다른 글

[Android-06]Toast  (0) 2017.12.01
[Android-05]Event - Click,Touch  (0) 2017.12.01
[Android-04]Layout  (0) 2017.11.30
[Android-03]xml과 java의 연결, 간단한 이벤트  (0) 2017.11.10
[Android-01]기본적인 프로젝트의 이해  (0) 2017.09.03

+ Recent posts