관리 메뉴

드럼치는 프로그래머

[안드로이드] 제2강좌 - 안드로이드 기본 레이아웃 본문

★─Programing/☆─Android

[안드로이드] 제2강좌 - 안드로이드 기본 레이아웃

드럼치는한동이 2011. 5. 24. 11:07

안드로이드 어플리케이션 기초

 

@ 가상 디바이스(AVD)

project ->API와 AVD API가 동일하여야 함

name

target - android API(위치기반 필요 없다면) // Google API(위치기반)

              ver. 2.x대는 서로 호환가능

SD 카드를 사용하지 않는 것은 특별히 선택하지 말길.. 속도가 느려짐. 32메가 밑으로..

skin - HVGA 그래픽 카드,종횡비가 다를 경우 밑에서 선택 가능

HardWare-필요한 하드웨어 추가 가능. 계속 변경 가능

 

@ Android project

file-new-other-android project next

 

project name 영문으로,툭수문자 금지

creat new - 새로운 프로젝트 생성

create from - 생성된 프로젝트 가져오기

           - 생성한 워크스페이스에서 작성된 프로젝트는 불러지지 않고, 다른 곳에 위치한 프로젝트를 불러들일 때 사용.

           - 불러와서 작성 후 저장한 프로젝트는 내 워크스페이스에 저장되는 것이 아니라 불러온 곳의 위치에 저장 됨.

build target - 가상 API에서 선택한 것 선택

application name -

package name -소문자로 생성. com.android.test

creat activity(클래스이름) - 대문자로 시작, 특수기호 안됨

 

빨간색 글씨 사라짐.

MIN SDK version : API level 번호를 적는다. 작동하기 위한 최소한의 버젼

finish

 

src 폴더- 소스 작성하는 곳

              andtest.java 열기

              import-내쪽에 이식 저장,    Activity;랑 Bundle;

              include-가져다 쓰는것

gen폴더 -패키지.. R.java->수정하면 안되는것, 리소스가 들어가 있음

res(리소스에서 아래폴더에 있는 폴더를 불러들일때는 확장자명을 작성하지 않는다)

     -layou-main.xml 버튼과 같은 ui컨트롤하는 곳

     -value-string

     -drawable-

 

 

========================================================================================================================================

src-com.android.test-Andtest.java

 

package com.android.test;

import android.app.Activity;
import android.os.Bundle;

public class Andtest extends Activity {         //클래스를 만들기 위해 class선언 , class권한을 주기 위해 public 선언 =누구나 사용할 수 있는 클래스

                                                                       //Activity상속을 받기 위해서 extends 선언
    /** Called when the activity is first created. */
    @Override                                      //oncreat가 Activity꺼라는 부모가 가져있는 메소드를 내가 변경하기 위해서 선언함. 선언시 컴파일러 빨라짐
    public void onCreate(Bundle savedInstanceState) {  //void는 반환하는 값이 없을 경우 사용. Bunlde<-data type
        super.onCreate(savedInstanceState); //Andtest
        setContentView(R.layout.main);   //resource 폴더안에 폴더는 확장자명 작성하지 않는다.
    }
}

 

 

//Andtest는 액티비티꺼,

1. @Override,

2.public void onCreate(Bundle savedInstanceState)원래 코드 그대로,

3.super.onCreate(savedInstanceState); 부모꺼 다시한번 호출,

4.setContentView(R.layout.main); 내가 작성하고 싶은대로

#자바는 두번 상속안됨

//oncreat는 OS가 사용하는 것이라서 public으로 선언

========================================================================================================================================

layout-main.xml

//activity>linearlayout>textview 가 존재.

 

<?xml version="1.0" encoding="utf-8"?>  //xml선언부 필요
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" //기본적 위치를 세로로 위치    horizontal 가로 .. ctrl+F11 은 가로세로 변환
    android:layout_width="fill_parent" //가로크기를 부모(activity)에 꽉차게
    android:layout_height="fill_parent"
    >
<TextView  //버튼과 같은 UI
    android:layout_width="fill_parent" //가로크기를 부모(linearlayout)에 꽉차게   
    android:layout_height="wrap_content" //높이는 글자를 포함한 만큼의 크기로
    android:text="@string/hello" //value-string폴더 안의 hello 다음 text가 화면에 출력됨
    />
</LinearLayout>

//최상의 루트노드는 하나만 있고 그안에 존대하여야 함. 또 중첩되면 안됨.

//xml 문서에 주석을 달 경우 <!    >와 같이 달아줘야 함. 일부분에서 일부분은 주석 불가능

========================================================================================================================================stristring.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, Andtest!</string>
    <string name="app_name">Project1</string>
</resources>

//텍스트를 관리함

========================================================================================================================================

AndroidManifest.xml

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.test"  //패키지 구조명
      android:versionCode="1"     //마켓에 올리기 위해서 버젼,이름,아이콘,라벨이 포함됨
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name"> //리소스를 불러올댄 확장자 사용 안함. icon.
        <activity android:name=".Andtest" //액티비티 이름으로 들어감.   클래스 앞에 .이 필요!!! 클래스명
                  android:label="@string/app_name">
            <intent-filter>  //서로 연결할 때 사용,,,액티비티가 2개이상이라면 이부분은 한번만 있으면 된다. 다른 액티비티에는 없어도 됨.
                <action android:name="android.intent.action.MAIN" /> //"안드로이드,인텐트,액션 안의 상수값"을  이용하라. 변경안됨. MAIN(대문자)=상수 
                <category android:name="android.intent.category.LAUNCHER" /> // ~.~.~.패키지 구조
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="7" />   //version level

</manifest>

 

========================================================================================================================================

 

실행시켜보기

project 밑에 화살표 누르고-> Run configuration->android application 하위 항목

 

-> project 선택->target tap으로 넘어감.

아래쪽에 emulater line option을    -noskin을 하면 스마트 폰 처럼 화면이 나옴

 

1.main.xml textview의 text에 글씨를 변경하면 화면에 변경 됨

===========================================================================================================================================

@@@과제@@@

 

 

<?xml version="1.0" encoding="utf-8" ?>  //xml 선언부
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" //기본 레이어를 세로로 설정
    android:layout_width="fill_parent"  //넓이를 부모와 같게
    android:layout_height="fill_parent" //길이를 부모와 같게
    android:background="#fff"> //배경색 지정
  <TextView android:layout_width="fill_parent"  
     android:layout_height="wrap_content"  //높이를 문자크기에 맞게
     android:text="충북대 학생 접속화면"
     android:textSize="30dp"  //사이즈 지정
     android:gravity="center" //위치지정
     android:textColor="#282828" //색상지정
     />
  <LinearLayout android:orientation="horizontal"  //레이아웃을 가로로 설정
       android:layout_width="fill_parent"
         android:layout_height="wrap_content">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="아이디 :"
        android:textColor="#ffaa00"
        />
    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="학번을 입력해주세요"
        />
    </LinearLayout> //가장 가까운 레이아웃을 종료
  <LinearLayout android:orientation="horizontal"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="비밀번호 :"
        android:textColor="#ffaa00"
        />
    <EditText android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:hint="비밀번호를 입력해주세요"
          />
    </LinearLayout>
    <Button android:layout_width="200dp"
      android:layout_height="wrap_content"
      android:textSize="25dp" 
      android:text="로그인"
      />

  </LinearLayout>

 

워크스페이스 들어간 담에 해당 프로젝트를 압축하면 됨.

============================================================================================================================================

@ AVD->setting->applications->unknown source가 체크되어있는지 확인(핸드폰과 연결되어있을때 넣을수 있음)

manege application->AVD에 설치된 APP을 확인 할 수 있음

 

@ 오른쪽 상단 ++ DDMS를 통하여 통화 상태 확인 가능

                      gpx,kml로 위도 경도 값을 불러올 수 있다.

@log cat - 어디서 에러가 있는지 알 수 있음.

@data-data안에 패키지 구조별로 설치된 모든 어플이 저장되어 있음.

@system을 삭제하면 안됨

@system의 font에서 pc 또는 핸드폰에 저장가능 (오른쪽 상단에 디스켓이나 핸드폰 클릭)

 

============================================================================================================================================


Comments