OpenFrameWork

오픈프레임워크_Day71

px 2015. 6. 24. 09:09

### : 목차 구분 기호
--- : 목차 내에 항목 구분 기호
@@@ : 태그 용도 
,,, : 같은 목차 내에 구분 기호

목차
1. 이론 및 정보
2. 설정 및 그 밖에
3. 소스코드 또는 실습
4. 과제

###################################
1. 이론 및 정보
-----------------------------------
* View - Activity 안에 들어가는 모든 요소는 View의 자식

http://developer.android.com/reference/android/view/View.html
위 사이트에서 View 메서드들을 확인함

View Group을 확인
http://developer.android.com/reference/android/view/ViewGroup.html
----------------------------------- 
Layout
http://developer.android.com/guide/topics/ui/declaring-layout.html

RelativeLayout은 상대적으로 배치를 해주는 역할
FragmentLayout은 한 화면에 넓은 화면에 메뉴와 내용을 같이 보여줌
----------------------------------- 
* 화면이동
Intent, 인텐트 이용
화면이동시 무언가를 들고갈 때 사용
화면이동을 어디로 할지에 대해서 정할 수 있음
----------------------------------- 
###################################
2. 설정 및 그 밖에
-----------------------------------
* 프로젝트 생성 
/LayoutApp
WorkSpace : ~\study\AndroidWork
-----------------------------------
* Activity 추가 방법

안드로이드 프로젝트 모든 환경설정을 담당
/LayoutApp/AndroidManifest.xml

해당 내용을 추가 하면서 클래스를 만들어야하는데 쉬운 방법으로 해보겠음








/LayoutApp/src/com/example/layoutapp/LinearActivity.java
생성됨


/LayoutApp/res/layout 에 파일 추가




xml파일은 소문자만 가능



/LayoutApp/res/layout/activity_linear.xml
생성됨
----------------------------------- 
* Activity 추가 방법 2 - 수동

클래스 만듬
/LayoutApp/src/com/example/layoutapp/RelativeActivity.java


만들어 놓은 것을 신고해야함

/LayoutApp/AndroidManifest.xml
아래 태그를 추가
<activity android:name="RelativeActivity"></activity>

/LayoutApp/src/com/example/layoutapp/RelativeActivity.java
안에 onCreate 메서드 오버라이딩

/LayoutApp/res/layout/activity_relative.xml
xml파일은 /LayoutApp/res/layout/activity_main.xml 복사함


----------------------------------- 

* XML Values File 추가


----------------------------------- 
* 폴더 만들고 이미지 넣음, 소문자 여야함
/LayoutApp/res/drawable
/LayoutApp/res/drawable/desert.jpg
/LayoutApp/res/drawable/penguins.jpg
/LayoutApp/res/drawable/tulips.jpg 
-----------------------------------  
###################################
3. 소스코드 또는 실습 
-----------------------------------
3-1
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/activity_main.xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
     
    <Button 
        android:text="LinearLayout"
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/btnLinear"/>"
    
    <Button 
        android:text="RelativeLayout"
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/btnRelative"/>
    
    <Button 
        android:text="FrameLayout"
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/btnFrame"/>
    
    <Button 
        android:text="TableLayout"
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/btnTable"/>
    
    <Button 
        android:text="GridLayout"
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/btnGrid"/>
</LinearLayout>
----------------------------------- 
3-2
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/MainActivity.java

package com.example.layoutapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener{

     @Override
     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          
          Button btnLinear = (Button)findViewById(R.id.btnLinear);
          Button btnRelative = (Button)findViewById(R.id.btnRelative);
          Button btnFrame = (Button)findViewById(R.id.btnFrame);
          Button btnTable = (Button)findViewById(R.id.btnTable);
          Button btnGrid = (Button)findViewById(R.id.btnGrid);
          
          btnLinear.setOnClickListener(this);
          btnRelative.setOnClickListener(this);
          btnFrame.setOnClickListener(this);
          btnTable.setOnClickListener(this);
          btnGrid.setOnClickListener(this);
     }
     
     @Override
     public void onClick(View v) {
          Intent intent = null;
          switch(v.getId()){
          case R.id.btnLinear:
               intent = new Intent(MainActivity.this, LinearActivity.class);
               break;
          case R.id.btnRelative:
               intent = new Intent(MainActivity.this, RelativeActivity.class);
               break;
          case R.id.btnFrame:
               break;
          case R.id.btnTable:
               break;
          case R.id.btnGrid:
          }
          if(intent != null)
               startActivity(intent);
     }
}
----------------------------------- 
3-3
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/activity_linear.xml

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="LinearLayout Test"
        android:textSize="20sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#AA0000"
            android:text="red" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#00AA00"
            android:text="green" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0000AA"
            android:text="blue" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#AAAA00"
            android:text="yellow" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="First" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Second" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Third" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Forth" />
    </LinearLayout>

</LinearLayout>
----------------------------------- 
3-4
WorkSpace : ~\study\AndroidWork
/LayoutApp/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.layoutapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="LinearActivity"></activity>
        <activity android:name="RelativeActivity"></activity>
    </application>

</manifest>
----------------------------------- 
3-5 
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/LinearActivity.java

package com.example.layoutapp;

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

public class LinearActivity extends Activity {

     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_linear);
     }

}
----------------------------------- 
3-6
WorkSpace : ~\study\AndroidWork
/LayoutApp/src/com/example/layoutapp/RelativeActivity.java

package com.example.layoutapp;

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

public class RelativeActivity extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_relative);
     }
}
----------------------------------- 
3-7 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/layout/activity_relative.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="RelativeLayout Test"
        android:textSize="20sp"
        />

    <TextView
        android:id="@+id/tvTypeHere"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvTitle"
        android:layout_marginTop="10dp"
        android:text="Type here : "
        />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tvTitle"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@id/tvTypeHere"
        android:id="@+id/etTypeHere"
         />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cancel"
        android:layout_below="@id/etTypeHere"
        android:layout_alignParentRight="true"
        android:id="@+id/btnCancle"
        />
   
    <Button
        android:text="OK"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/etTypeHere"
        android:layout_toLeftOf="@id/btnCancle"
        />
    
    <Spinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/times"
        android:layout_below="@id/btnCancle"
        android:layout_alignParentLeft="true"
        android:id="@+id/sp1"
        />   
        
    <Spinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/dates"
        android:layout_below="@id/btnCancle"
        android:layout_toRightOf="@id/sp1"
        />   
</RelativeLayout>
----------------------------------- 
3-8 
WorkSpace : ~\study\AndroidWork
/LayoutApp/res/values/arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="times">
        <item>12:12 pm</item>
        <item>12:12 오후</item>
        <item>pm 12:12</item>
    </string-array>
   
    <string-array name="dates">
        <item>2015.06.24. 화요일</item>
        <item>6.24.2015.tue</item>
        <item>2015/06/15</item>
        <item>Tue 2015/06/15</item>
    </string-array>
</resources>
----------------------------------- 
###################################
4. 과제
-----------------------------------
-----------------------------------
###################################
5. 과제 해결
-----------------------------------
-----------------------------------
###################################
6. 기타
----------------------------------- 
-----------------------------------