2010년 1월 27일 수요일

Hello LinearLayout 살펴보기

자~ 오늘은 이전에 작성해보았던 LinearLayout 에 작성된 코드에 대해 알아보도록 하죠

기본적으로 레이아웃은 XML 코드로 작성이 되어 있습니다.

인터페이스를 구성하기 위해선 이 xml 코드를 작성할 필요가 있지요.

먼저 LinearLayout 은 자식 뷰 요소들이 수평 또는 수직적으로 배치되는 GroupView 라고 합니다.


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
android:orientation="vertical"
   
android:layout_width="fill_parent"
   
android:layout_height="fill_parent">

LinearLayout 의 배치는 orientation 으로 vertical(수평) 또는 horizontal(수직) 로 결정해주시면 됩니다.

layout_width 와 layout_height 에서 액티비티 내의 뷰의 크기를 설정해줄 수 있습니다.

기본적으로 fill_parent 와 wrap_content 가 제공됩니다.

fill_parent 는 화면에 꽉 차도록, wrap_content는 각 View에 필요한만큼만 화면을 차지하도록 하게 합니다.

<TextView
           
android:text="red"
           
android:gravity="center_horizontal"
           
android:background="#aa0000"
           
android:layout_width="wrap_content"
           
android:layout_height="fill_parent"
           
android:layout_weight="1"/>

각각의 LinearLayout에는 위에서 언급했듯이 각각의 View들을 배치할 수 있습니다. 여러View가 있지만 먼저 TextView를 보도록 하지요.(차후에 다른 View들에 대한 언급도 하도록 하겠습니다.)

TextView는 이름에서 알 수 있듯이 텍스트, 즉 글을 표시하기 위한 View 입니다. 각 속성에 의해서 화면에 표시할 값을 정해줄 수 있죠.

public void onCreate(Bundle savedInstanceState) {
   
super.onCreate(savedInstanceState);
    setContentView
(R.layout.main);
}

Hello LinearLayout 클래스의 onCreate 메소드입니다.

기본적인 코드인걸 알 수 있습니다. 이 메소드 안의 setContentView 는 xml파일을 읽어들여 화면에
표시해주는 역할을 하는 메소드 입니다. R.layout.main 은 main.xml 파일을 가리키고 있지요. 즉 나중에 여러개의 액티비티를 생성하실 경우 layout에 새로운 xml 을 작성하셔서 R.layout.해당파일이름 으로 연결하시면 사용이 가능합니다.

댓글 없음:

댓글 쓰기