package com.android.textview3;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.graphics.Color;

public class TextViewDemo3 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //main.xml 등록
        setContentView(R.layout.main);
        
        //사전에 등록한id를 통해 TextView객체 호출
        TextView text =(TextView)findViewById(R.id.text);
        text.setBackgroundColor(Color.BLUE);
        text.setTextColor(Color.WHITE);
        
    }
}
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.android.textview3;

public final class R {    //상속불가
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int text=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>



'Android > 기본' 카테고리의 다른 글

Android 간단한 이벤트2  (0) 2012.04.28
Android 간단한 이벤트  (0) 2012.04.28
android 기본 (TextView)2 - 객체를 직접입력하는 방법  (0) 2012.04.28
android 기본 (TextView)  (0) 2012.04.28
Android Program Structure  (0) 2012.04.28
package com.android.textview2;

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

public class TextViewDemo2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //textView 객체생성  //android.widget.TextView import시켜줌
        TextView tv = new TextView(this);  //this -> TextViewDemo2 (Activity(화면) 상속)
        //문자열 입력
        tv.setText("텍스트 직접 입력");
        //생성된 TextView를 등록 
        setContentView(tv);
    }
}



'Android > 기본' 카테고리의 다른 글

Android 간단한 이벤트2  (0) 2012.04.28
Android 간단한 이벤트  (0) 2012.04.28
android 기본 (TextView)3  (0) 2012.04.28
android 기본 (TextView)  (0) 2012.04.28
Android Program Structure  (0) 2012.04.28
src/ com.adroid.text / TextViewDemo1.java
package com.android.textview3;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.graphics.Color;

public class TextViewDemo3 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //main.xml 등록
        setContentView(R.layout.main);
        
        //사전에 등록한 id를 통해 Textview 객체 호출
        TextView text = (TextView)findViewById(R.id.text);
        text.setBackgroundColor(Color.GRAY);
        text.setTextColor(Color.WHITE);
        
    }
}

gen/com.adroid.text /R.java

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.android.textview3;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int text=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}
res/ values/ string.xml
<!--?xml version="1.0" encoding="utf-8"?-->
<resources>

    <string name="hello">Hello World, TextViewDemo3!</string>
    <string name="app_name">03TextViewDemo3</string>

</resources>
res/ layout/ main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>



'Android > 기본' 카테고리의 다른 글

Android 간단한 이벤트2  (0) 2012.04.28
Android 간단한 이벤트  (0) 2012.04.28
android 기본 (TextView)3  (0) 2012.04.28
android 기본 (TextView)2 - 객체를 직접입력하는 방법  (0) 2012.04.28
Android Program Structure  (0) 2012.04.28

안드로이드 프로그램 구조


1) 뷰

뷰(View)는 사용자와 직접 상호작용을 할 UI를 의미한다.


2) 액티비티

보통 액티비티와 UI화면은 일대일 대응 관계를 갖고 시스템 혹은 사용자로부터 시작된 이벤트에 반응한다.


3) 인텐트  

컨포넌트간의 통신 수단이며 메시지에 대한 상세한 정보를 가진다. 예를 들면 주소록 목록 액티비티에서 편집 액티비티를 호출할 때 누구의 주소를 어떤 식으로 편집하라는 지시가 인텐트에 실려 전달된다.


4) 서비스  (백그라운드 기능)

서비스는 주로 백그라운드에서 돌아가는 실행코드로, 일단 실행되면 휴대폰이 꺼질 때까지 돌아간다. 서비스는 일반적으로 사용자 인터페이스가 없다.

예) MP3 플레이어 (음악을 듣다가 전화가 오면 전화를받고 통화후 mp3 재생 + 웹서핑하면서 mp3 음악듣기)


5) 브로드캐스트 리시버(BroadcastReceiver) (평상시 동작을 안하다가 특정이벤트에 반응)

만약 애플리케이션이 전화가 오거나 문자메시지 수신과 같은 이벤트를 받거나 반응하기를 원한다면 반드시 브로드캐스트 리시버로서 등록되어 있어야만 한다. 신호만 대기할 뿐 UI를 따로 가지지는 않으므로 신호 수신시 적절한 액티비티를 띄워 내용을 전달한다.


6) 컨텐트 프로바이더 (타 어플에서 데이터를 공유 : 단 보안이 필요한 데이터는 하면안됨)

다른 응용 프로그램을 위해 자신의 데이터를 제공한다. 안드로이드는 보안이 엄격하여 다른 응용프로그램의 데이터를 함부로 액세스 하지 못하도록 되어 있다. 응용프로그램 간에 데이터를 공유할 수 있는 합법적인 유일한 장치가 바로 콘텐트 프로바이더 이다.



안드로이드 사용 가능한 구성 요소

1) 데이터 보관

2) 네트워크

3) 멀티미디어

4) GPS

5) 전화서비스



크기 : 안드로이드에서 위젯의 패딩값과 같이 각종 크기를 표현할 때 사용


px : 화면의 기본단위 pixel, 해상도에 따라 크기가 달라짐

dp(dip) : 기기 기준 픽셀(device-dependent pixels), 인치당 160개의 점이 있는 디스플레이에서 1dp = 1px, dp단위로 지정하면 해상도만큼 길이가 늘어나 해상도에 상관없이 비슷한 크기로 보임

sp : 배율 기준 픽셀(scale-dependent pixels), sp는 사용자가 지정한 글꼴의 기본 크기에 비례해 크기가 변경


색상 xml

#RGB             #F00 (12비트 빨강)

#ARGB           #8F00 (12비트 투명도 50% 빨강)

#RRGGBB      #FF00FF (24비트 보라색)

#AARRGGBB  #FFFF0000 (24비트 불투명한 빨강)

                    #FF808080 (24비트 불투명한 회색)

                    #8000FF00 (24비트 투명도 50% 초록)

                    #80FF00FF (24비트 투명도 50% 보라색)

                    AA (Alpha) 투명도 (00..FF)

                    00은 100% 투명이고, FF는 완전 불투명을 의미

                    RR (Red) 빨강의 강도 (00..FF)

                    00은 빨강색이 하나도 없음을 의미

                    GG (Green) 초록의 강도 (00..FF)

                    BB (Blue) 파랑의 강도 (00..FF)


클래스에서는 *코드에서 색상 값은 정수(int)


이미지 포멧

  

      res/drawable-hdpi/ic_launcher.png   고해상도 이미지 폴더

      res/drawable-ldpi/ ic_launcher.png   저해상도 이미지 폴더

      res/drawable-mdpi/ ic_launcher.png   중해상도 이미지 폴더


PNG(Portable Network Graphics)           .png           권장됨(무손실)

JPG(Joint Photographic Experts Group    .jpg, .jpeg        권장되지는 않음(유손실)

GIF(Graphics Interchange Format)          .gif                  사용하지 않는 것이 좋음


주의점

blue.png <=> blue.jpg 충돌

*blue를 id로 사용하기때문에 확장자가 틀려도 충돌이난다.


Monk.jpg

*대문자를 불허한다!!! monk.jpg로 넣어야한다.


고해상도 아이콘크기 72*72

중해상도 아이콘크기 48*48

저해상도 아이콘크기 36*36


안드로이드 reference

http://developer.android.com/


뷰,텍스트뷰,레이블



안드로이드의 입력방법 2방법


1. 직접생성 입력

  ex) src/ com.android.textview3/ TextViewDemo2.java 에 바로 등록


2. main.xml에 작업한후 읽어오기 (권장)

  R클래스 - 자동으로 자원의 관리해서 연

  gen/ com.android.textview2/ R.java 에 (id:static final.)main.xml 객체들의 위치가 등록  

  src/ com.android.textview2/ TextViewDemo2.java 에서 R.id


'Android > 기본' 카테고리의 다른 글

Android 간단한 이벤트2  (0) 2012.04.28
Android 간단한 이벤트  (0) 2012.04.28
android 기본 (TextView)3  (0) 2012.04.28
android 기본 (TextView)2 - 객체를 직접입력하는 방법  (0) 2012.04.28
android 기본 (TextView)  (0) 2012.04.28

+ Recent posts