[13-D2][UI 설계] Spinner, RadioGroup, RadioButton, CheckBox

[01] 주차 요금 계산(Spinner, RadioGroup, RadioButton, CheckBox)

1. 이미지
   - View --> ImageView: 이미지를 넣을 수 있는 TextView Clss
   - View --> ImageView --> ImageButton: 이미지를 넣을 수 있는 버튼 클래스
  

2. 체크 박스
   - View --> TextView --> Button --> CompoundButton
     --> RadioButton --> CheckBox
   - 취미같은 다중 선택 가능

 

3. 라디오 버튼
   - View --> TextView --> Button --> CompoundButton --> RadioButton
   - 성별같은 단일 선택만 가능
   - RadioGroup에 의해 RadioButton의 그룹화 가능
  

 


[02] 주차 요금 계산 TextView, Button, EditText, LinearLayout)

1. 프로젝트 생성
   - Project Type: Android Project
     Project name: Parking_4
     Application name: Parking_4
     Package name: android.Parking
     Create Activity(Activity name): Parking
     Min SDK Version: 4


1) AndroidManifest.xml 설정
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="android.Parking"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".Parking"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="3" />

</manifest>

 


2. 문자열 리소스 정의

>>>>> res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, Parking!</string>
    <string name="app_name">주차료 계산</string>
    <string name="spiTime_prompt">시간 선택</string>   
    <string-array name="times">
        <item>0</item>
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
        <item>6</item>
        <item>7</item>
        <item>8</item>
        <item>9</item>
        <item>10</item>
        <item>11</item>
        <item>12</item>
        <item>13</item>
        <item>14</item>
        <item>15</item>
        <item>16</item>
        <item>17</item>
        <item>18</item>
        <item>19</item>
        <item>20</item>
        <item>21시간 이상</item>             
    </string-array>
</resources>

 

 

3. View(콘트롤) 생성 및 배치

>>>>> res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout android:id="@+id/LinearLayout01"
        android:orientation="horizontal"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <TextView android:id = "@+id/txt01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="시간당 금액: " android:textSize="20px" />
        <EditText android:id="@+id/edtPrice"
            android:layout_width="80px" android:layout_height="wrap_content"
            android:maxLength = "5" android:textSize="20px"
            android:text="0"/>
    </LinearLayout>
    <LinearLayout android:id="@+id/LinearLayout02"
        android:orientation="horizontal"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        >      
        <TextView android:id = "@+id/txt02"  
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="경과된 시간: " android:textSize="20px"  />
        <Spinner android:id="@+id/spiTime"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:entries="@array/times"
            android:prompt="@string/spiTime_prompt"
           />
                  
    </LinearLayout>
    <LinearLayout android:id="@+id/LinearLayout03"
        android:orientation="horizontal"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        >      
        <RadioGroup
            android:id="@+id/rdg01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:orientation = "horizontal">
        <TextView  
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="구분: " android:textSize="20px" />
           
            <RadioButton android:text="경차" android:id="@+id/rdo01"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textSize="20px" />
            <RadioButton android:text="일반" android:id="@+id/rdo02"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textSize="20px" />
            <RadioButton android:text="승합차" android:id="@+id/rdo03"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textSize="20px" />                       
         </RadioGroup>
    </LinearLayout>     
   
    <LinearLayout android:id="@+id/LinearLayout06"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <TextView android:text="할인 선택: "
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:textSize="20px" />

    </LinearLayout>
   
    <LinearLayout android:id="@+id/LinearLayout04"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <CheckBox android:text="회원" android:id="@+id/chk01"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="20px" />
        <CheckBox android:text="국가 유공자" android:id="@+id/chk02"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="20px" />
        <CheckBox android:text="다자녀" android:id="@+id/chk03"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="20px" />          
    </LinearLayout>
   
    <LinearLayout android:id="@+id/LinearLayout05" android:background="#ffff00"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
       
        <TextView android:text="  원금: 0" android:id="@+id/txtWonkum"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="20px" android:textColor="#000000"/>
        <TextView android:text="  할인 금액: 0" android:id="@+id/txtDc"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="20px" android:textColor="#000000"/>
    </LinearLayout>
    <LinearLayout android:id="@+id/LinearLayout06"  android:background="#90ee90"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
       
        <TextView android:text="  지불 금액: 0"  android:id="@+id/txtPayment"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textSize="20px" android:textColor="#000000"/>
    </LinearLayout>   
   
</LinearLayout>

 


4. Class(이벤트) 작성
   - 이벤트 등록은 생성자에서 불가능.

>>>>> src/android.Parking.Parking.java
package android.parking;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

public class Parking extends Activity  implements OnClickListener{
  
    EditText edtPrice;
    Spinner spi;
    RadioButton rdo01;
    RadioButton rdo02;
    RadioButton rdo03;
   
    CheckBox chk01;
    CheckBox chk02;
    CheckBox chk03;       
   
    TextView txtWonkum;
    TextView txtDc;
    TextView txtPayment;

    int payment = 0;
    int wonkum = 0;
    int dc = 0;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
      
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        edtPrice = (EditText) findViewById(R.id.edtPrice);
        edtPrice.setOnClickListener(this); 
       
        spi = (Spinner)findViewById(R.id.spiTime);
        spi.setOnItemSelectedListener(
            new OnItemSelectedListener(){
                public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    int index = spi.getSelectedItemPosition();
                   
                    // 시간당 금액
                    wonkum = new Integer((edtPrice.getText()).toString()).intValue();
                   
                    // 선택된 시간
                    TextView selItem = (TextView)spi.getSelectedView();
                    // 선택된 시간을 정수로 변경
                    int _time = new Integer(selItem.getText().toString()).intValue();

                    // 주차시간 계산
                    wonkum = wonkum * _time;
                   
                    display();                   
                }
                public void onNothingSelected(AdapterView<?> arg0) {
                    wonkum = 0;
                }
            }
        );
       

        rdo01 = (RadioButton)findViewById(R.id.rdo01);
        rdo01.setOnClickListener(this);
        rdo02 = (RadioButton)findViewById(R.id.rdo02);
        rdo02.setOnClickListener(this);
        rdo03 = (RadioButton)findViewById(R.id.rdo03);
        rdo03.setOnClickListener(this);
       
        chk01 = (CheckBox)findViewById(R.id.chk01);
        chk01.setOnClickListener(this);
        chk02 = (CheckBox)findViewById(R.id.chk02);
        chk02.setOnClickListener(this);
        chk03 = (CheckBox)findViewById(R.id.chk03);
        chk03.setOnClickListener(this);

        txtWonkum = (TextView) findViewById(R.id.txtWonkum);
        txtDc = (TextView) findViewById(R.id.txtDc);
        txtPayment = (TextView) findViewById(R.id.txtPayment);

        display();       
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.edtPrice){
            wonkum = 0;
        }else if(v.getId() == R.id.rdo01){
            dc = (int)Math.round(wonkum * 0.5);
        }else if(v.getId() == R.id.rdo02){
            dc = (int)Math.round(wonkum * 0.1);
        }else if(v.getId() == R.id.rdo03){
            dc =  (int)Math.round(wonkum * 0.0);
        }
       
        if((v.getId() == R.id.chk01) && (chk01.isChecked() == true)){
            dc = dc + (int)Math.round(wonkum * 0.1);
        }
        if((v.getId() == R.id.chk01) && (chk01.isChecked() == false)){
            dc = dc - (int)Math.round(wonkum * 0.1);
        }
       
        if((v.getId() == R.id.chk02) && (chk02.isChecked() == true)){
            dc = dc + (int)Math.round(wonkum * 0.1);
        }
        if((v.getId() == R.id.chk02) && (chk02.isChecked() == false)){
            dc = dc - (int)Math.round(wonkum * 0.1);
        }
       
        if((v.getId() == R.id.chk03) && (chk03.isChecked() == true)){
            dc = dc + (int)Math.round(wonkum * 0.1);
        }
        if((v.getId() == R.id.chk03) && (chk03.isChecked() == false)){
            dc = dc - (int)Math.round(wonkum * 0.1);
        }
       
        display();

    }

    public void display(){
        payment = wonkum - dc;
       
        txtWonkum.setText("원금: " + wonkum);
        txtDc.setText("   할인 금액: " + dc);
        txtPayment.setText("지불 금액: " + payment);
    }

}

 


 

Posted by ▶파이팅◀


[12-D2][UI 설계] EditText와 TableLayout

[01] AbsoluteLayout Layout
       - AbsoluteLayout: View가 x,y좌표에 의해서 배치, 레이아웃이 깨질 수 있고 화면의
        구성요소가 서로 잘 맞아 떨어저야함으로 잘 사용되지 않는다.
        안드로이드 SDK 1.5 R1부터 폐기 대상으로 분류되어 더이상 사용되지 않는다.

 

 


[02] TableLayout Layout

   - 행과 열의 격자를 이용해 View의 배치.
   - 아래의 레이아웃 특성을 조합하여 사용

     android:stretchColumns="1"             : 두번째 컴럼의 크기를 남는 공간으로 늘림(확장).
     android:stretchColumns=" 늘리려는 column 번호(0~), *"
     android:shrinkColumns=" 필요한 공간만 사용하고 줄이고자 하는 column 번호(0~), *"

     android:stretchColumns="1" android:shrinkColumns="*": 모든 컬럼의 값을 전부
     필요한 만큼만 사용하고 1번째 컬럼을 남은 공간으로 전부 확대

     android:collapseColumns=" 숨기고자 하는 column 번호(0~), *"

     android:layout_span=" 차지하려는 Column 수", 셀 합치기
     android:layout_span="2": 컬럼 2개를 합침.


 
 
     이름:[   ]의 경우 2번째 입력란을 확대함.
     android:layout_marginTop="60px"        : 뷰를 부모의 위쪽에서 일정 간격 떨어짐
     android:layout_alignParentTop="true"   : 뷰를 부모에서 상단에 배치
     android:layout_centerHorizontal="true" : 뷰를 부모에서 수평 중앙에 배치
     android:layout_alignParentRight="true" : 뷰를 부모에서 오른쪽에 배치
     android:layout_alignParentLeft="true"  : 뷰를 부모에서 왼쪽에 배치
     android:layout_centerVertical="true"   : 뷰를 부모에서 수직 중앙에 배치
     android:layout_centerInParent="true"   : 뷰를 수직, 수평의 중앙에 배치
     android:layout_alignParentBottom="true": 뷰를 부모에서 하단에 배치

 

 
 
 

 

[04] EditText와 TableLayout 실습

1. 프로젝트 생성
   - Project Type: Android Project
     Project name: TableLayoutTest_4
     Application name: TableLayoutTest_4
     Package name: test.TableLayoutTest
     Create Activity(Activity name): TableLayoutTest
     Min SDK Version: 4

 


2. 문자열 리소스 정의
>>>>> res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="main">
    <item name="android:textSize">10pt</item>
</style>
<style name="standard" parent="main">
    <item name="android:textColor">#000000</item>
</style>
<style name="title" parent="main">
    <item name="android:textColor">#00FF00</item>
</style>

</resources>

 


2. 문자열 리소스 정의

>>>>> res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">TableLayoutTest!</string>
    <string name="app_name">TableLayoutTest</string>
</resources>

 


3. View(콘트롤) 생성 및 배치

>>>>> res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/LinearLayout01"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="fill_parent">
    <TableLayout
    android:id="@+id/TableLayout01"
    xmlns:android="http://schemas.android.com/apk/res/android
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*" android:gravity="center_vertical"
    android:padding = "50px">
    <TableRow
        android:id="@+id/TableRow00"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <TextView
            android:id="@+id/txv00"
            android:text="패스워드를  입력하세요."
            android:layout_span="3" android:gravity="center_horizontal"
            style="@style/title" />
    </TableRow>
    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/btn01"
            android:text="1" style="@style/standard" />
        <Button
            android:id="@+id/btn02"
            android:text="2" style="@style/standard" />
        <Button
            android:id="@+id/btn03"
            android:text="3" style="@style/standard" />
    </TableRow>
    <TableRow
        android:id="@+id/TableRow02"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <Button
            android:id="@+id/btn04"
            android:text="4" style="@style/standard" />
        <Button
            android:id="@+id/btn05"
            android:text="5" style="@style/standard" />
        <Button
            android:id="@+id/btn06"
            android:text="6" style="@style/standard" />
    </TableRow>
    <TableRow
        android:id="@+id/TableRow03"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <Button
            android:id="@+id/btn07"
            android:text="7" style="@style/standard" />
        <Button
            android:id="@+id/btn08"
            android:text="8" style="@style/standard" />
        <Button
            android:id="@+id/btn09"
            android:text="9" style="@style/standard" />
    </TableRow>
    <TableRow
        android:id="@+id/TableRow04"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <Button
            android:id="@+id/btn10"
            android:text="0"
            android:layout_column="0" style="@style/standard" />
        <Button
            android:id="@+id/btn11"
            android:text="*"
            android:layout_column="1" style="@style/standard" />
        <Button
            android:id="@+id/btn12"
            android:text="#"
            android:layout_column="2" style="@style/standard" />     
    </TableRow>
        </TableLayout>
       
    <LinearLayout android:id="@+id/LinearLayout02"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingLeft ="0px" >
        <EditText
            android:id="@+id/edt00"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="PASS" android:editable="false"
            android:lines="1"
            android:text="@+id/edt00"
            style="@style/standard"
            android:password = "false" android:maxLength = "4"
            android:focusable = "false"/>
        <Button
            android:id="@+id/btnDel"
            android:text="DELETE"
            style="@style/standard"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />     
        <Button
            android:id="@+id/btn13"
            android:text="OK"
            style="@style/standard"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" /> 
    </LinearLayout>

</LinearLayout>

 


4. 이벤트 작성

>>>>> TableLayoutTest.java
package test.TableLayoutTest;

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

import android.util.Log;

public class TableLayoutTest extends Activity implements OnClickListener{
  
 Button btn01;
 Button btn02;
 Button btn03;
 Button btn04;
 Button btn05;
 Button btn06;
 Button btn07;
 Button btn08;
 Button btn09;
 Button btn10;
 Button btn11;
 Button btn12;
    Button btnDel;
   
 EditText edt00;
 String str;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        btn01 = (Button)findViewById(R.id.btn01);
        btn01.setOnClickListener(this);        
        btn02 = (Button)findViewById(R.id.btn02);
        btn02.setOnClickListener(this);  
        btn03 = (Button)findViewById(R.id.btn03);
        btn03.setOnClickListener(this);  
        btn04 = (Button)findViewById(R.id.btn04);
        btn04.setOnClickListener(this);  
        btn05 = (Button)findViewById(R.id.btn05);
        btn05.setOnClickListener(this);          
        btn06 = (Button)findViewById(R.id.btn06);
        btn06.setOnClickListener(this);        
        btn07 = (Button)findViewById(R.id.btn07);
        btn07.setOnClickListener(this);  
        btn08 = (Button)findViewById(R.id.btn08);
        btn08.setOnClickListener(this);  
        btn09 = (Button)findViewById(R.id.btn09);
        btn09.setOnClickListener(this);  
        btn10 = (Button)findViewById(R.id.btn10);
        btn10.setOnClickListener(this);
        btn11 = (Button)findViewById(R.id.btn11);
        btn11.setOnClickListener(this);
        btn12 = (Button)findViewById(R.id.btn12);
        btn12.setOnClickListener(this);
        btnDel = (Button)findViewById(R.id.btnDel);
        btnDel.setOnClickListener(this);
       
        edt00 = (EditText)findViewById(R.id.edt00);
        str = "";
       
        edt00.setText("");
       
    }
   
    @Override
    public void onClick(View v) {
        String val = "";
        // TODO Auto-generated method stub
        if(v.getId() == R.id.btnDel){
            val = edt00.getText().toString();
            int len = val.length();
            if (len > 0){
                val = val.substring(0, len-1);
            }
            str = val;
        }else{
            Button btn = (Button)v;
            str = str + (String)btn.getText();
        }
        edt00.setText(str);

    }   
}

 


 

 
 

Posted by ▶파이팅◀


[11-D2][UI 설계] 지역화(국제화), ImageView, RelativeLayout, 한글 Encoding

[01] 지역화(국제화)
     - layout 설계시 values-en이 기본 사용됨.
     - 실행시 대상 기기의 지역에 따라 선택되어 자동 실행됨.
     - 지역 변경: menu -- setting -- Locale & Text -- Select locale -- 한국어
    
            
1. 문자열 데이터의 지역화
   - 사용 가능 값: en, fr, es, zh, ja, ko, de,fi
   - 영어권: /res/values-en/string.xml
   - 한국어: /res/values-ko/string.xml

 

2. 이미지 데이터의 지역화
   - 사용 가능 값: en, fr, es, zh, ja, ko, de,fi
   - 영어권: /res/drawable-en-ldpi, /res/drawable-en-mdpi, /res/drawable-en-hdpi
   - 한국어: /res/drawable-ko-ldpi, /res/drawable-ko-mdpi, /res/drawable-ko-hdpi

 


[02] ImageView
   - import android.widget.ImageView;
   - View --> ImageView: 이미지를 넣을 수 있는 View Class
   - View --> ImageView --> ImageButton: 이미지를 넣을 수 있는 버튼 클래스
   - jpg, png, gif 지원, png는 알파채널이 있어 투명도를 적용 할 수 있는 기능도 지원함.
   - SDK 1.5이하에서는 모든 이미지를 해상도와 상관 없이 /res/drawable폴더에 저장해야 했음.
   - SDK 1.6이상에서는 해상도별 이미지 저장 폴더가 구분되며 가상 머쉰이 자동으로 선별하여 사용함.
     drawable_ldpi: 120px의 이미지, 아이콘은 36px,
     drawable_mdpi: 160px의 이미지, 아이콘은 48px,
     drawable_hdpi: 240px의 이미지, 아이콘은 72px
   - android:src: 출력될 이미지의 경로 지정, @drawable/ID형식으로 이미지의 id 지정.
   - maxHeight, maxWidth: 이미지의 최대 크기, 종횡비가 유지됨으로 출력되는 이미지의 가로세로비가
     다르게 출력 될 수 있다.
   - adjustViewBounds: 출력되는 이미지의 종횡비 유지 여부 지정.

 

 

[03] RelativeLayout
     - 다른 콘트롤에 비례해서 콘트롤의 위치 지정.
     - 뷰를 위치를 설정하기위해 '|' 선언 가능.

1. 부모뷰를 기준으로 설정
     android:layout_marginRight="20px"      : 뷰를 부모의 오른쪽에서 일정 간격 떨어짐
     android:layout_marginTop="60px"        : 뷰를 부모의 위쪽에서 일정 간격 떨어짐
     android:layout_alignParentTop="true"   : 뷰를 부모에서 상단에 배치
     android:layout_centerHorizontal="true" : 뷰를 부모에서 수평 중앙에 배치
     android:layout_alignParentRight="true" : 뷰를 부모에서 오른쪽에 배치
     android:layout_alignParentLeft="true"  : 뷰를 부모에서 왼쪽에 배치
     android:layout_centerVertical="true"   : 뷰를 부모에서 수직 중앙에 배치
     android:layout_centerInParent="true"   : 뷰를 수직, 수평의 중앙에 배치
     android:layout_alignParentBottom="true": 뷰를 부모에서 하단에 배치

2. 주변에 배치된 뷰를 기준으로
     android:layout_toRightOf="@id/idname"    : 특정 뷰의 오른쪽에 배치
     android:layout_toLeftOf="@id/idname"     : 특정 뷰의 외쪽에 배치
     android:layout_alignBaseline="@id/idname": 뷰와 같은 라인에 배치
     android:layout_below="@id/idname"        : 뷰의 아래에 배치
     android:layout_above="@id/idname"        : 뷰의 위에 배치
     android:layout_alignRight="@id/idname"   : 뷰의 오른쪽에 배치
     android:layout_alignLeft="@id/idname"    : 뷰의 왼쪽에 배치
     android:layout_alignTop="@id/idname"     : 뷰의 위쪽에 배치


   - 예) [TEL][SMS]의 경우
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnSms"
        android:layout_marginLeft="1px"
        android:text="SMS"
        android:textSize="16px"
        android:layout_alignParentRight="true"
    />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnTel"
        android:layout_marginLeft="6px"
        android:text="TEL"
        android:textSize="16px"
        android:layout_toLeftOf="@id/btnSms"
        />

 

 

[03] 실습

1. 프로젝트 생성
   - Project Type: Android Project
     Project name: Relative_4
     Application name: Relative_4
     Package name: test.Relative
     Create Activity(Activity name): Relative
     Min SDK Version: 4

 

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

<!-- android:gravity: 자식 뷰의 정렬
      android:layout_gravity: 부모를 기준으로한 정렬   -->
<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:gravity="center_horizontal" android:background="#FF0000" android:layout_height="200px">
<Button android:id="@+id/Button01" android:layout_height="wrap_content" android:text="SMS" android:layout_width="100px"
></Button>
<Button android:id="@+id/Button02" android:layout_height="wrap_content" android:layout_below="@+id/Button01" android:text="TEL" android:layout_width="100px"></Button>
</RelativeLayout>
<RelativeLayout android:id="@+id/RelativeLayout02" android:layout_width="fill_parent" android:layout_height="150px" android:background="#00FF00">
<Button android:id="@+id/Button03" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="SMS"></Button>

<Button android:layout_toRightOf="@+id/Button03"
android:id="@+id/Button04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEL"></Button>

</RelativeLayout>
<RelativeLayout android:id="@+id/RelativeLayout03" android:layout_width="fill_parent" android:layout_height="150px" android:background="#0000FF">
<Button android:id="@+id/Button05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TEL" android:layout_alignParentRight="true" android:layout_alignParentBottom="true"></Button>

<Button android:layout_toLeftOf="@+id/Button05" android:id="@+id/Button06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SMS" android:layout_alignParentBottom="true"></Button>
</RelativeLayout>


</LinearLayout>

 

[04] 실습

1. 프로젝트 생성
   - Project Type: Android Project
     Project name: ImageViewTest_4
     Application name: ImageViewTest_4
     Package name: test.ImageViewTest
     Create Activity(Activity name): ImageViewTest
     Min SDK Version: 4

 


2. 이미지 저장 및 변환
   - Ubuntu - GIMP Image Editor
   - Ubuntu 10.04부터는 우분투 소프트웨어 센터에서 설치해야함.

 


3. 문자열

>>>>> res/values-en/string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, ImageViewTest!</string>
    <string name="app_name">ImageViewTest</string>
<string name="txvName">Ga Gil Dong</string>
<string name="txvAddress">Seoul Korea </string>
<string name="btnCall">CALL</string>
</resources>

 


>>>>> res/values-ko/string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">ImageViewTest!</string>
    <string name="app_name">이미지뷰어 테스트</string>
<string name="txvName">가 길 동</string>
<string name="txvAddress">서울 대한민국 </string>
<string name="btnCall">전화</string>
</resources>

 


3. View 생성 및 배치
   - Layout 파일명은 영어 소문자 및 숫자, _만 가능함.

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

<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
                   android:src="@drawable/memo"
android:id="@+id/img"/>


<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/img" android:id="@+id/TextView01" android:text="@string/txvEtc" android:paddingTop="10px"></TextView><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txvName" android:text="@string/txvName" android:layout_toRightOf="@+id/img" android:paddingLeft="10px"></TextView>

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btnCall" android:layout_alignParentRight="true" android:id="@+id/btnCall"></Button>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txvAddress" android:text="@string/txvAddress" android:layout_toRightOf="@id/img" android:layout_below="@+id/txvTel" android:paddingLeft="10px"></TextView>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/img" android:id="@+id/txvTel" android:layout_below="@id/txvName" android:text="@string/txvTel" android:paddingLeft="10px"></TextView>

</RelativeLayout>
</LinearLayout>

 


4. Class(event)

>>>>> src/test.LinearLayoutTest.LinearLayoutTest.java
package test.ImageViewTest;

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

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

 


[참고] Eclipse의 한글 Encoding 설정
       - Windows XP에서 작업된 한글이 깨질경우 아래의 인코딩을 지정합니다.
       - Eclipse -- Window -- Preferences -- General -- Contents Types -- Text -- Java Source File -- Default Encoding
             'euc-kr'로 지정 후 UPDATE

 


 

Posted by ▶파이팅◀

블로그 이미지
Let's start carefully from the beginning
▶파이팅◀

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함