2011년 1월 28일 금요일

[Android Course][English][Theme] - Android Tab to apply a background image




Tab typically apply a background image is simple.
In other words, as follows: "setBackgroundColor ()" Applying is easy.


'm_tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#534512"));'
However, I want several properties as shown below was applied.

- 'Touch the color or image when you'
- 'Touch Up When the color or image'
- 'Tab color or image when it is focusing on'
...

As shown above in order to provide a base should be combined with the Android Control.






※ Example Code
- TapView_Custom.java
public class TapView_Custom extends TabActivity implements OnTabChangeListener {
    /** Called when the activity is first created. */

    private TabHost m_tabHost = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setContentView(R.layout.tapview_custom_layout);
       
        /** TabHost ID */
        m_tabHost= (TabHost)findViewById(android.R.id.tabhost); 
        TabSpec aaa_TabSpec = m_tabHost.newTabSpec("aaa"); 
        TabSpec bbb_TabSpec = m_tabHost.newTabSpec("bbb");
        TabSpec ccc_TabSpec = m_tabHost.newTabSpec("ccc");
       
        LayoutInflater vi1 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LayoutInflater vi2 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LayoutInflater vi3 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View View_1 = (View)vi1.inflate(R.layout.tab_row_item, null);        View View_2 = (View)vi2.inflate(R.layout.tab_row_item, null);
        View View_3 = (View)vi3.inflate(R.layout.tab_row_item, null);
        LinearLayout Layout_1 = (LinearLayout)View_1.findViewById(R.id.LinearLayout01);
        LinearLayout Layout_2 = (LinearLayout)View_2.findViewById(R.id.LinearLayout01);
        LinearLayout Layout_3 = (LinearLayout)View_3.findViewById(R.id.LinearLayout01);
        Layout_1.setBackgroundResource(R.drawable.tab_1_bg);
        Layout_2.setBackgroundResource(R.drawable.tab_2_bg);
        Layout_3.setBackgroundResource(R.drawable.tab_3_bg);
       
        ImageView iv_1 = (ImageView)View_1.findViewById(R.id.icon);
        ImageView iv_2 = (ImageView)View_2.findViewById(R.id.icon);
        ImageView iv_3 = (ImageView)View_3.findViewById(R.id.icon);
       
        TextView tv_1 = (TextView)View_1.findViewById(R.id.text);
        TextView tv_2 = (TextView)View_2.findViewById(R.id.text);
        TextView tv_3 = (TextView)View_3.findViewById(R.id.text);
        tv_1.setText("aaa");
        tv_2.setText("bbb");
        tv_3.setText("ccc");
       
        aaa_TabSpec.setIndicator(View_1);
        aaa_TabSpec.setContent(new Intent(this,test_activity.class)); 
        bbb_TabSpec.setIndicator(View_2);
        bbb_TabSpec.setContent(new Intent(this,test_activity.class)); 
        ccc_TabSpec.setIndicator(View_3);
        ccc_TabSpec.setContent(new Intent(this,test_activity.class)); 
       
       /** 탭을 TabHost 에 추가한다 */
        m_tabHost.addTab(aaa_TabSpec);
        m_tabHost.addTab(bbb_TabSpec);
        m_tabHost.addTab(ccc_TabSpec);
       
        m_tabHost.getTabWidget().setCurrentTab(0); 
    }
}

- tapview_custom_layout.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">
 <TabHost
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@android:id/tabhost">
  <LinearLayout
    android:id="@+id/LinearLayout01"
   android:orientation="vertical"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"> 
   <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_weight="1">
   </FrameLayout> 
 
    <TabWidget
    android:id="@android:id/tabs"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
   </TabWidget>
  </LinearLayout>
 </TabHost>

</LinearLayout>


- tab_row_item.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="wrap_content"
 android:id="@+id/LinearLayout01"
 android:orientation="vertical">
 <ImageView
  android:id="@+id/icon"
  android:layout_width="33dip"
  android:layout_height="30dip"
  android:layout_marginTop="3dip"
  android:scaleType="fitXY"
  android:layout_gravity="center"
  android:background="@drawable/icon" >
 </ImageView>
 <TextView
  android:id="@+id/text"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:layout_marginLeft="5dip"
  android:layout_marginRight="5dp"
  android:textSize="15dip"
  android:layout_gravity="center" />

</LinearLayout>


- tab_1_bg.xml
('res - drawable' folder, create a file in)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:state_selected="true"
  android:drawable="@drawable/color_green"/>

 <item
  android:state_pressed="true"
  android:drawable="@drawable/color_yellow"/>

 <item
  android:state_focused="false"
  android:drawable="@drawable/color_white"/>
</selector>


- tab_2_bg.xml
('res - drawable' folder, create a file in)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:state_selected="true"
  android:drawable="@drawable/color_green"/>

 <item
  android:state_pressed="true"
  android:drawable="@drawable/color_yellow"/>

 <item
  android:state_focused="false"
  android:drawable="@drawable/color_white"/>
</selector>


- tab_3_bg.xml
('res - drawable' folder, create a file in)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:state_selected="true"
  android:drawable="@drawable/color_green"/>

 <item
  android:state_pressed="true"
  android:drawable="@drawable/color_yellow"/>

 <item
  android:state_focused="false"
  android:drawable="@drawable/color_white"/>
</selector>


In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)

[Android 강좌][Korean][테마] - Tab 배경이미지 적용 방법




일반적으로 Tab의 배경 이미지 적용은 간단하다.
즉, 아래와 같이 "setBackgroundColor()" 를 적용하면 간단하다.

'm_tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#534512"));'
하지만, 내가 원하는 것은 아래와 같이 여러 속성을 적용하고자 한다.

- 'Touch 했을 때 색상 or 이미지'
- 'Touch Up 했을 때 색상 or 이미지'
- 'Tab에 포커싱 되어 있을 때 색상 or 이미지'
...

위와 같이 하기 위해서는 기본으로 제공되는 Android Control을 조합해야 한다.





※ Example Code
- TapView_Custom.java
public class TapView_Custom extends TabActivity implements OnTabChangeListener {
    /** Called when the activity is first created. */

    private TabHost m_tabHost = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setContentView(R.layout.tapview_custom_layout);
       
        /** TabHost ID */
        m_tabHost= (TabHost)findViewById(android.R.id.tabhost); 
        TabSpec aaa_TabSpec = m_tabHost.newTabSpec("aaa"); 
        TabSpec bbb_TabSpec = m_tabHost.newTabSpec("bbb");
        TabSpec ccc_TabSpec = m_tabHost.newTabSpec("ccc");
       
        LayoutInflater vi1 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LayoutInflater vi2 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LayoutInflater vi3 = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View View_1 = (View)vi1.inflate(R.layout.tab_row_item, null);        View View_2 = (View)vi2.inflate(R.layout.tab_row_item, null);
        View View_3 = (View)vi3.inflate(R.layout.tab_row_item, null);
        LinearLayout Layout_1 = (LinearLayout)View_1.findViewById(R.id.LinearLayout01);
        LinearLayout Layout_2 = (LinearLayout)View_2.findViewById(R.id.LinearLayout01);
        LinearLayout Layout_3 = (LinearLayout)View_3.findViewById(R.id.LinearLayout01);
        Layout_1.setBackgroundResource(R.drawable.tab_1_bg);
        Layout_2.setBackgroundResource(R.drawable.tab_2_bg);
        Layout_3.setBackgroundResource(R.drawable.tab_3_bg);
       
        ImageView iv_1 = (ImageView)View_1.findViewById(R.id.icon);
        ImageView iv_2 = (ImageView)View_2.findViewById(R.id.icon);
        ImageView iv_3 = (ImageView)View_3.findViewById(R.id.icon);
       
        TextView tv_1 = (TextView)View_1.findViewById(R.id.text);
        TextView tv_2 = (TextView)View_2.findViewById(R.id.text);
        TextView tv_3 = (TextView)View_3.findViewById(R.id.text);
        tv_1.setText("aaa");
        tv_2.setText("bbb");
        tv_3.setText("ccc");
       
        aaa_TabSpec.setIndicator(View_1);
        aaa_TabSpec.setContent(new Intent(this,test_activity.class)); 
        bbb_TabSpec.setIndicator(View_2);
        bbb_TabSpec.setContent(new Intent(this,test_activity.class)); 
        ccc_TabSpec.setIndicator(View_3);
        ccc_TabSpec.setContent(new Intent(this,test_activity.class)); 
       
       /** 탭을 TabHost 에 추가한다 */
        m_tabHost.addTab(aaa_TabSpec);        m_tabHost.addTab(bbb_TabSpec);
        m_tabHost.addTab(ccc_TabSpec);
       
        m_tabHost.getTabWidget().setCurrentTab(0); 
    }
}

- tapview_custom_layout.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">
 <TabHost
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@android:id/tabhost">
  <LinearLayout
    android:id="@+id/LinearLayout01"
   android:orientation="vertical"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"> 
   <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_weight="1">
   </FrameLayout> 
 
    <TabWidget
    android:id="@android:id/tabs"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
   </TabWidget>
  </LinearLayout>
 </TabHost>

</LinearLayout>


- tab_row_item.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="wrap_content"
 android:id="@+id/LinearLayout01"
 android:orientation="vertical">
 <ImageView
  android:id="@+id/icon"
  android:layout_width="33dip"
  android:layout_height="30dip"
  android:layout_marginTop="3dip"
  android:scaleType="fitXY"
  android:layout_gravity="center"
  android:background="@drawable/icon" >
 </ImageView>
 <TextView
  android:id="@+id/text"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:layout_marginLeft="5dip"
  android:layout_marginRight="5dp"
  android:textSize="15dip"
  android:layout_gravity="center" />

</LinearLayout>


- tab_1_bg.xml
('res - drawable'폴더에 파일을 생성)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:state_selected="true"
  android:drawable="@drawable/color_green"/>

 <item
  android:state_pressed="true"
  android:drawable="@drawable/color_yellow"/>

 <item
  android:state_focused="false"
  android:drawable="@drawable/color_white"/>
</selector>


- tab_2_bg.xml
('res - drawable'폴더에 파일을 생성)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:state_selected="true"
  android:drawable="@drawable/color_green"/>

 <item
  android:state_pressed="true"
  android:drawable="@drawable/color_yellow"/>

 <item
  android:state_focused="false"
  android:drawable="@drawable/color_white"/>
</selector>


- tab_3_bg.xml
('res - drawable'폴더에 파일을 생성)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
  android:state_selected="true"
  android:drawable="@drawable/color_green"/>

 <item
  android:state_pressed="true"
  android:drawable="@drawable/color_yellow"/>

 <item
  android:state_focused="false"
  android:drawable="@drawable/color_white"/>
</selector>

추가로 문의 사항이나, 궁금한 점이 계시면 연락주세요.
(joonryang@gmail.com)
※ 도움이 되셨다면, ^^. 맨 위 광고클릭 좀..ㅎㅎ

[Android Course][English][Theme] - Android Tab at the bottom to




Tab typically located at the top of the screen.
The 'layout' if you want to change, if change is shown below.
('TabWidget' and 'FrameLayout' change of position is the point.
And android: layout_weight = "1" You can help the better.)




※ Example Code
- TapView_Default.java
public class TapView_Default extends TabActivity {

    private TabHost m_tabHost = null;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.tapview_default_layout);
       
        /** TabHost ID */
        m_tabHost= (TabHost)findViewById(android.R.id.tabhost); 
        TabSpec aaa_TabSpec = m_tabHost.newTabSpec("aaa"); 
        TabSpec bbb_TabSpec = m_tabHost.newTabSpec("bbb");
        TabSpec ccc_TabSpec = m_tabHost.newTabSpec("ccc");
        aaa_TabSpec.setIndicator("aaa", getResources().getDrawable(R.drawable.games)); 
        aaa_TabSpec.setContent(new Intent(this,test_activity.class)); 
        bbb_TabSpec.setIndicator("bbb", getResources().getDrawable(R.drawable.games)); 
        bbb_TabSpec.setContent(new Intent(this,test_activity.class)); 
        ccc_TabSpec.setIndicator("ccc", getResources().getDrawable(R.drawable.games)); 
        ccc_TabSpec.setContent(new Intent(this,test_activity.class)); 

        /** 탭을 TabHost 에 추가한다 */
        m_tabHost.addTab(aaa_TabSpec);
        m_tabHost.addTab(bbb_TabSpec);
        m_tabHost.addTab(ccc_TabSpec);

        /** TabHost 에 포함된 Tab의 색깔 변경가능 */
        m_tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#534512")); 
        m_tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#4E4E9C"));
        m_tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.parseColor("#6E8E1C"));
        m_tabHost.getTabWidget().setCurrentTab(0); 
    }
}

- tapview_default_layout.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">
        
 <TabHost
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@android:id/tabhost">
  <LinearLayout
    android:id="@+id/LinearLayout01"
   android:orientation="vertical"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"> 

   <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_weight="1">
   </FrameLayout>

    <TabWidget
    android:id="@android:id/tabs"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
   </TabWidget>

  </LinearLayout>
 </TabHost>

</LinearLayout>

In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)

[Android 강좌][Korean][테마] - Tab 하단에 위치 시키기




일반적으로 Tab은 화면의 상단에 위치한다.
이러한 'layout'을 변경하고자 한다면, 아래와 같이 변경하면 된다.
( 'TabWidget' 과 'FrameLayout' 의 위치 변경이 포인트입니다.
그리고 android:layout_weight="1"를 해주시면 더욱 좋습니다.)


 
※ Example Code
- TapView_Default.java
public class TapView_Default extends TabActivity {

    private TabHost m_tabHost = null;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.tapview_default_layout);
       
        /** TabHost ID */
        m_tabHost= (TabHost)findViewById(android.R.id.tabhost); 
        TabSpec aaa_TabSpec = m_tabHost.newTabSpec("aaa"); 
        TabSpec bbb_TabSpec = m_tabHost.newTabSpec("bbb");
        TabSpec ccc_TabSpec = m_tabHost.newTabSpec("ccc");
        aaa_TabSpec.setIndicator("aaa", getResources().getDrawable(R.drawable.games)); 
        aaa_TabSpec.setContent(new Intent(this,test_activity.class)); 
        bbb_TabSpec.setIndicator("bbb", getResources().getDrawable(R.drawable.games)); 
        bbb_TabSpec.setContent(new Intent(this,test_activity.class)); 
        ccc_TabSpec.setIndicator("ccc", getResources().getDrawable(R.drawable.games)); 
        ccc_TabSpec.setContent(new Intent(this,test_activity.class)); 

        /** 탭을 TabHost 에 추가한다 */
        m_tabHost.addTab(aaa_TabSpec);
        m_tabHost.addTab(bbb_TabSpec);
        m_tabHost.addTab(ccc_TabSpec);

        /** TabHost 에 포함된 Tab의 색깔 변경가능 */
        m_tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#534512")); 
        m_tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#4E4E9C"));
        m_tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.parseColor("#6E8E1C"));
        m_tabHost.getTabWidget().setCurrentTab(0); 
    }
}

- tapview_default_layout.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">
        
 <TabHost
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@android:id/tabhost">
  <LinearLayout
    android:id="@+id/LinearLayout01"
   android:orientation="vertical"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"> 

   <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_weight="1">
   </FrameLayout>

    <TabWidget
    android:id="@android:id/tabs"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
   </TabWidget>

  </LinearLayout>
 </TabHost>

</LinearLayout>

추가로 문의 사항이나, 궁금한 점이 계시면 연락주세요.
(joonryang@gmail.com)
※ 도움이 되셨다면, ^^. 맨 위 광고클릭 좀..ㅎㅎ

[Android Course][English][Theme] - Android Basic Tab function




Android through the TabHost tab provides a container.
Information on the screen if you have a lot to express,
Use Tab to expand the screen effects can be expressed by using the information.

Some of the screen to display more than one tab, and
When you click the tab to the tab screen shows the structure belongs.
Tab to configure the following items should be used.
(1) TabHost classes: tap the button and tab detail across the entire tab container
(2) TabWidget Class: Tab button to manage the list.
Tab button to enter a text string, if necessary, set the icon
(3) FrameLayout container: Tab content management. For each tab of a widget inside a FrameLayout



※ Example Code
- TapView_Default.java
public class TapView_Default extends TabActivity {

    private TabHost m_tabHost = null;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.tapview_default_layout);
       
        /** TabHost ID */
        m_tabHost= (TabHost)findViewById(android.R.id.tabhost); 
        TabSpec aaa_TabSpec = m_tabHost.newTabSpec("aaa"); 
        TabSpec bbb_TabSpec = m_tabHost.newTabSpec("bbb");
        TabSpec ccc_TabSpec = m_tabHost.newTabSpec("ccc");
        aaa_TabSpec.setIndicator("aaa", getResources().getDrawable(R.drawable.games)); 
        aaa_TabSpec.setContent(new Intent(this,test_activity.class)); 
        bbb_TabSpec.setIndicator("bbb", getResources().getDrawable(R.drawable.games)); 
        bbb_TabSpec.setContent(new Intent(this,test_activity.class)); 
        ccc_TabSpec.setIndicator("ccc", getResources().getDrawable(R.drawable.games)); 
        ccc_TabSpec.setContent(new Intent(this,test_activity.class)); 

        /** 탭을 TabHost 에 추가한다 */
        m_tabHost.addTab(aaa_TabSpec);
        m_tabHost.addTab(bbb_TabSpec);
        m_tabHost.addTab(ccc_TabSpec);

        /** TabHost 에 포함된 Tab의 색깔 변경가능 */
        m_tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#534512")); 
        m_tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#4E4E9C"));
        m_tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.parseColor("#6E8E1C"));
        m_tabHost.getTabWidget().setCurrentTab(0); 
    }
}

- tapview_default_layout.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">
        
 <TabHost
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@android:id/tabhost">
  <LinearLayout
    android:id="@+id/LinearLayout01"
   android:orientation="vertical"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"> 
    <TabWidget
    android:id="@android:id/tabs"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
   </TabWidget>

   <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_weight="1">
   </FrameLayout> 
  </LinearLayout>
 </TabHost>

</LinearLayout>

In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)

[Android 강좌][Korean][테마] - Android 기본 Tab 기능




안드로이드에서는 TabHost 컨테이너를 통해 탭 기능을 제공합니다.
화면에 표현하기에 많은 내용이 있다면,
Tab을 사용해 화면을 확장하는 효과를 사용하여 내용을 표현할 수 있습니다.

화면의 일부에 여러 개 탭을 표시하고,
탭을 클릭하면 해당 탭에 속한 화면을 보여주는 구조입니다.
탭을 구성하기 위해서 아래의 항목들을 사용해야 합니다.
(1) TabHost 클래스 : 탭 버튼과 탭 내용을 아우르는 전체 탭 컨테이너
(2) TabWidget 클래스 : 탭 버튼 목록을 관리.
탭 버튼은 텍스트 문자열이 들어가고, 필요한 경우에는 아이콘을 설정
(3) FrameLayout 컨테이너 : 탭 내용을 관리. 각 탭 내용은 FrameLayout 내부에 하나의 위젯



※ Example Code
- TapView_Default.java
public class TapView_Default extends TabActivity {

    private TabHost m_tabHost = null;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.tapview_default_layout);
       
        /** TabHost ID */
        m_tabHost= (TabHost)findViewById(android.R.id.tabhost); 
        TabSpec aaa_TabSpec = m_tabHost.newTabSpec("aaa"); 
        TabSpec bbb_TabSpec = m_tabHost.newTabSpec("bbb");
        TabSpec ccc_TabSpec = m_tabHost.newTabSpec("ccc");
        aaa_TabSpec.setIndicator("aaa", getResources().getDrawable(R.drawable.games)); 
        aaa_TabSpec.setContent(new Intent(this,test_activity.class)); 
        bbb_TabSpec.setIndicator("bbb", getResources().getDrawable(R.drawable.games)); 
        bbb_TabSpec.setContent(new Intent(this,test_activity.class)); 
        ccc_TabSpec.setIndicator("ccc", getResources().getDrawable(R.drawable.games)); 
        ccc_TabSpec.setContent(new Intent(this,test_activity.class)); 

        /** 탭을 TabHost 에 추가한다 */
        m_tabHost.addTab(aaa_TabSpec);
        m_tabHost.addTab(bbb_TabSpec);
        m_tabHost.addTab(ccc_TabSpec);

        /** TabHost 에 포함된 Tab의 색깔 변경가능 */
        m_tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#534512")); 
        m_tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#4E4E9C"));
        m_tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.parseColor("#6E8E1C"));
        m_tabHost.getTabWidget().setCurrentTab(0); 
    }
}

- tapview_default_layout.xml
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">
        
 <TabHost
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@android:id/tabhost">
  <LinearLayout
    android:id="@+id/LinearLayout01"
   android:orientation="vertical"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"> 
    <TabWidget
    android:id="@android:id/tabs"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
   </TabWidget>
 
   <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_weight="1">
   </FrameLayout> 
  </LinearLayout>
 </TabHost>

</LinearLayout>


추가로 문의 사항이나, 궁금한 점이 계시면 연락주세요.
(joonryang@gmail.com)
※ 도움이 되셨다면, ^^. 맨 위 광고클릭 좀..ㅎㅎ

2011년 1월 25일 화요일

[Android Course][English][Theme] -"Google Translation (Google Translate) API " translated by




Google Translation (Google Translate) API by making a simple translator, let's see.

1. "Google Translate" library Download.
: Google Translate API to use is a priority need to add external libraries.
Visit the following sites will receive the appropriate library files.

http://code.google.com/p/google-api-translate-java/downloads/list

2. Project added to the library
: "Project - Properties - Java Build Path - Libraries - Add JARs ..."
ex) Add the downloaded jar file => google-api-translate-java-0.92.jar

3. Permission (permission) settings
: "AndroidManifest.xml" added to the file permissions.


4. Example : Java Source Code























public void ExeConnection() {
// "Str" : Translate a sentence or word
String str = m_Search_EditText.getText().toString();
// "getstr" : Translated phrase or word
String getstr = new String();

try{
Translate.setHttpReferrer("http://androidhuman.tistory.com");
/ / translated running
getstr = Translate.execute(str, Language.KOREAN, Language.ENGLISH);
}catch(Exception e){
e.printStackTrace();
}
m_View_TextView.setText(getstr);
}

5. Description
- public String execute(String text, Language from, Language to)
: From language to language into written text to a string.
Returns the translated text.
To translate the language of the sentence if it is not fixed auto-sensing (Language.AUTO_DETECT) can be used.

- Translate.setHttpReferrer
: Before using the API translation is the method I need to write.
URL of your blog or other site, please put the address is.
(If you miss the code does not perform the translation.)

In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)

[Android 강좌][Korean][테마] - "구글번역(Google Translate) API"를 이용한 번역




구글번역(Google Translate) API를 이용하여 간단한 번역기를 만드는 것에 대해 알아보도록 하겠습니다.

1. "Google Translate" library Download.
: Google Translate API를 사용하기 위해서는 우선 외부 라이브러리를 추가해주어야 합니다.
아래의 사이트를 방문하여 해당 라이브러리 파일을 받도록 합니다.
http://code.google.com/p/google-api-translate-java/downloads/list

2. Project에 library 추가
: "Project - Properties - Java Build Path - Libraries - Add JARs ..."
ex) 다운받은 jar 파일 추가=> google-api-translate-java-0.92.jar


3. 권한(permission) 설정
: "AndroidManifest.xml" 파일에 권한 추가.


4. Example : Java Source Code























public void ExeConnection() {
// "Str" : 번역할 문장 or 단어
String str = m_Search_EditText.getText().toString();
// "getstr" : 번역된 문장 or 단어
String getstr = new String();

try{
Translate.setHttpReferrer("http://androidhuman.tistory.com");
// 변역 실행
getstr = Translate.execute(str, Language.KOREAN, Language.ENGLISH);
}catch(Exception e){
e.printStackTrace();
}
m_View_TextView.setText(getstr);
}

5. 설명
- public String execute(String text, Language from, Language to)
: from 언어로 작성된 text 문자열을 to 언어로 번역합니다.
번역된 텍스트를 반환합니다.
번역할 문장의 언어가 정해져 있지 않을 경우 자동 감지 (Language.AUTO_DETECT)를 사용할 수 있습니다.

- Translate.setHttpReferrer
: 번역 API를 사용하기 전에 꼭 적어주어야 하는 메소드입니다.
자신의 블로그나 기타 URL 사이트 주소를 넣어주시면 됩니다.
(이 코드를 빼먹으면 번역이 수행되지 않습니다.)

추가로 문의 사항이나, 궁금한 점이 계시면 연락주세요.
(joonryang@gmail.com)
※ 도움이 되셨다면, ^^. 맨 위 광고클릭 좀..ㅎㅎ

2011년 1월 16일 일요일

[Android Course][English][Theme] - Android free game engine used - Rokon




1. 'Rokon library' Download.
: http://code.google.com/p/rokon/downloads/list
The above site "Rokon library" and "Rokon library Source Code" and so on.

2. 'Rokon library' Eclipse Porject Add
















 3. 'Rokon library' Framework and description
1) Structure














2) 'Rokon library' Framework for a replacement document
: http://coscup.org/2010/slides/15_3_1300_android_game_engine.pdf


4. Sample Code.
1) 'Image Load' method











- "Image_Load_Activity.java"
public class Image_Load_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures.load();
        setScene(scene = new GameScence());
    } // End of onLoadComplete
}

- "GameScence.java"
public class GameScence extends Scene {
    private FixedBackground background;
    public GameScence() {
        super();
        setBackground(background = new FixedBackground(Textures.background));
    } // End of GameScence
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {
    } // End of onReady
   
}

- "Textures.java"
public class Textures {
    public static TextureAtlas atlas;
    public static Texture background;
    public static void load() {
        atlas = new TextureAtlas();
        atlas.insert(background = new Texture("background.png"));
        atlas.complete();
    } // End of load
   
}

2) 'Image' on the screen, showing how












- "Add_Image_Activity.java"
public class Add_Image_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence1 scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures1.load();
        setScene(scene = new GameScence1());
    } // End of onLoadComplete
}

- "GameScence1.java"
public class GameScence1 extends Scene {
    private FixedBackground background;
    private Sprite bob, bob2, bob3;
   
    public GameScence1() {
        super(1,3);
        setBackground(background = new FixedBackground(Textures1.background));
       
        // Create the Bob sprites.
        bob = new Sprite(100, 220, Textures1.bob.getWidth(), Textures1.bob.getHeight());
        bob.setTexture(Textures1.bob);
        bob2 = new Sprite(100, 180, Textures1.bob.getWidth(), Textures1.bob.getHeight());
        bob2.setTexture(Textures1.bob);
        bob3 = new Sprite(100, 260, Textures1.bob.getWidth(), Textures1.bob.getHeight());
        bob3.setTexture(Textures1.bob);
        // Add the Bob sprites to the first layer.

        add(0, bob);
        add(0, bob2);
        add(0, bob3);
    } // End of GameScence
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {

     bob3.moveTo(450, 100, 5000);
     bob.moveTo(450, 100, 4000);
     bob2.moveTo(450, 100, 3000);
    } // End of onReady
   
}

- "Textures1.java"
public class Textures1 {
    public static TextureAtlas atlas1;
    public static Texture background, bob;
    public static void load() {
        atlas1 = new TextureAtlas();
        atlas1.insert(background = new Texture("background1.png"));
        atlas1.insert(bob = new Texture("android.png"));
        atlas1.complete();
    } // End of load
   
}

3) 'Image' and "Touch Move" to













- "Touch_Image_Activity.java"
public class Touch_Image_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence2 scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures2.load();
        setScene(scene = new GameScence2());
    } // End of onLoadComplete
}

- "GameScence2.java"
public class GameScence2 extends Scene {
    private FixedBackground background;
    private Sprite bob;
   
    public GameScence2() {

        super(1,1);
        setBackground(background = new FixedBackground(Textures2.background));
       
        // Create the Bob sprites.
        bob = new Sprite(100, 220, Textures2.bob.getWidth(), Textures2.bob.getHeight());
        bob.setTexture(Textures2.bob);
        // Add the Bob sprites to the first layer.

        add(0, bob);

    } // End of GameScence2
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {
    } // End of onReady
   
    public void onTouchDown(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // This is called when you press down on the screen.
    }

    public void onTouchMove(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // This is called when you move your finger over the screen.
     //(ie pretty much every frame if your holding your finger down)
        // Here we'll just make Bob follow your finger.
        bob.x = x - (Textures2.bob.getWidth() / 2);
        bob.y = y - (Textures2.bob.getHeight() / 2);
    }

    public void onTouchUp(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // And this is called when you stop pressing.
    }
   
}

- "Textures2.java"
public class Textures2 {
    public static TextureAtlas atlas1;
    public static Texture background, bob;
    public static void load() {
        atlas1 = new TextureAtlas();
        atlas1.insert(background = new Texture("background1.png"));
        atlas1.insert(bob = new Texture("android.png"));
        atlas1.complete();
    } // End of load
   
}


4) 'Image' and "Touch" changes depending on how













- "Modifiers_Use_Activity.java"
public class Modifiers_Use_Activity extends RokonActivity  {
 public static final float GAME_WIDTH = 480f;
 public static final float GAME_HEIGHT = 320f;
 private GameScence3 scene;
    public void onCreate() {
        debugMode();
        forceFullscreen();
        forceLandscape();
        setGameSize(GAME_WIDTH, GAME_HEIGHT);
        setDrawPriority(DrawPriority.PRIORITY_VBO);
        setGraphicsPath("textures/");
        createEngine();
    } // End of onCreate
   
    public void onLoadComplete() {
        Textures3.load();
        setScene(scene = new GameScence3());
    } // End of onLoadComplete
}

- "GameScence3.java"
public class GameScence3 extends Scene {
    private FixedBackground background;
    private Sprite bob;
    private ColorModifier modifier;
   
    public GameScence3() {

        super(1,3);
        setBackground(background = new FixedBackground(Textures3.background));
       
        // Create the Bob sprites.
        bob = new Sprite(100, 220, Textures3.bob.getWidth(), Textures3.bob.getHeight());
        bob.setTexture(Textures3.bob);
        // Add the Bob sprites to the first layer.

        add(0, bob);
        // And create the modifier.
        modifier = new ColorModifier();
    } // End of GameScence
    @Override
    public void onGameLoop() {
    } // End of onGameLoop
    @Override
    public void onPause() {
    } // End of onPause
    @Override
    public void onResume() {
    } // End of onResume
    @Override
    public void onReady() {
    } // End of onReady
   
    public void onTouchUp(float x, float y, MotionEvent event, int pointerCount, int pointerId) {
        // Add your modifier to the sprite.
        bob.addModifier(modifier);
    }
   
}

- "Textures3.java"
public class Textures3 {
    public static TextureAtlas atlas1;
    public static Texture background, bob;
    public static void load() {
        atlas1 = new TextureAtlas();
        atlas1.insert(background = new Texture("background1.png"));
        atlas1.insert(bob = new Texture("android.png"));
        atlas1.complete();
    } // End of load
   
}

In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)