위와 같이 탑에 메뉴를 넣기 원한다면, 아래와 같이 사용해 보면 좋을거 같습니다.
onCreate() 에 선언
mainTabListenerOn(); // menuMain1 이미지 버튼 5개에 관한 클래스
버튼 이름은 mainMenu1 , 2,3,4...
inculde 이름은 Main_menu1,2,3,4....
간단하게 처리가능합니다. :)
...
버튼 클릭시 이벤트
public void mainTabListenerOn() {
findViewById(R.id.mainMenu1).setOnClickListener(
new ImageButton.OnClickListener() {
public void onClick(View v) {
mainContentToggle(v);
}
});
findViewById(R.id.mainMenu2).setOnClickListener(
new ImageButton.OnClickListener() {
public void onClick(View v) {
mainContentToggle(v);
}
});
findViewById(R.id.mainMenu3).setOnClickListener(
new ImageButton.OnClickListener() {
public void onClick(View v) {
mainContentToggle(v);
}
});
findViewById(R.id.mainMenu4).setOnClickListener(
new ImageButton.OnClickListener() {
public void onClick(View v) {
mainContentToggle(v);
}
});
findViewById(R.id.mainMenu5).setOnClickListener(
new ImageButton.OnClickListener() {
public void onClick(View v) {
mainContentToggle(v);
}
});
}
public void mainContentToggle(View v) {
findViewById(R.id.main_tab1).setVisibility(View.INVISIBLE);
findViewById(R.id.main_tab2).setVisibility(View.INVISIBLE);
findViewById(R.id.main_tab3).setVisibility(View.INVISIBLE);
findViewById(R.id.main_tab4).setVisibility(View.INVISIBLE);
findViewById(R.id.main_tab5).setVisibility(View.INVISIBLE);
if (v.getId() == R.id.mainMenu2) {
findViewById(R.id.main_tab2).setVisibility(View.VISIBLE);
} else if (v.getId() == R.id.mainMenu3) {
findViewById(R.id.main_tab3).setVisibility(View.VISIBLE);
} else if (v.getId() == R.id.mainMenu4) {
findViewById(R.id.main_tab4).setVisibility(View.VISIBLE);
} else if (v.getId() == R.id.mainMenu5) {
findViewById(R.id.main_tab5).setVisibility(View.VISIBLE);
} else {
findViewById(R.id.main_tab1).setVisibility(View.VISIBLE);
}
findViewById(R.id.mainMenu1).setBackgroundResource(
R.drawable.category_menu1_off);
findViewById(R.id.mainMenu2).setBackgroundResource(
R.drawable.category_menu2_off);
findViewById(R.id.mainMenu3).setBackgroundResource(
R.drawable.category_menu3_off);
findViewById(R.id.mainMenu4).setBackgroundResource(
R.drawable.category_menu4_off);
findViewById(R.id.mainMenu5).setBackgroundResource(
R.drawable.category_menu5_off);
if (v.getId() == R.id.mainMenu2)
v.setBackgroundResource(R.drawable.category_menu2_on);
else if (v.getId() == R.id.mainMenu3)
v.setBackgroundResource(R.drawable.category_menu3_on);
else if (v.getId() == R.id.mainMenu4)
v.setBackgroundResource(R.drawable.category_menu4_on);
else if (v.getId() == R.id.mainMenu5)
v.setBackgroundResource(R.drawable.category_menu5_on);
else
v.setBackgroundResource(R.drawable.category_menu1_on);
}
main.xml
<LinearLayout android:layout_width="fill_parent"
android:layout_height="34dip" xmlns:android="http://schemas.android.com/apk/res/android"
android:textColor="#FFFFFF" android:layout_marginTop="-5px"
android:background="@drawable/cartoon_viewpage_bg_tit"
android:layout_gravity="center_vertical|center_horizontal"
>
<Button android:id="@+id/mainMenu1"
android:layout_width="100px"
android:layout_height="wrap_content" android:background="@drawable/category_menu1_off"
android:layout_weight="1"
android:layout_gravity="center_vertical"
/>
<Button android:id="@+id/mainMenu2"
android:layout_width="100px"
android:layout_height="wrap_content" android:background="@drawable/category_menu2_off"
android:layout_weight="1"
android:layout_gravity="center_vertical"
/>
<Button android:id="@+id/mainMenu3"
android:layout_width="100px"
android:layout_height="wrap_content" android:background="@drawable/category_menu3_off"
android:layout_weight="1"
android:layout_gravity="center_vertical"
/>
<Button android:id="@+id/mainMenu4"
android:layout_width="100px"
android:layout_height="wrap_content" android:background="@drawable/category_menu4_off"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
<Button android:id="@+id/mainMenu5"
android:layout_width="100px"
android:layout_height="wrap_content" android:background="@drawable/category_menu5_off"
android:layout_weight="1"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
<FrameLayout android:layout_below="@+id/mainLayoutFrame"
android:id="@+id/mainLayoutContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include layout="@layout/main_tab1"
android:id="@+id/main_tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="@layout/main_tab2"
android:id="@+id/main_tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible"/>
<include layout="@layout/main_tab3"
android:id="@+id/main_tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible"/>
<include layout="@layout/main_tab4"
android:id="@+id/main_tab4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible" />
<include layout="@layout/main_tab5"
android:id="@+id/main_tab5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible" />
</FrameLayout>
main_tab1 , 2, 3, 4, 5 . 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">
<TextView android:id="@+id/main_menu2" android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="40px"
android:text="메인 탭 2"
android:textColor="#FFFFFF" android:gravity="center"
android:drawablePadding="10px"
android:textStyle="bold" android:duplicateParentState="false" />
</LinearLayout>
'개발도구 > aOS - 안드로이드 개발' 카테고리의 다른 글
[안드로이드] textview bold 볼드 만들기 (0) | 2011.05.26 |
---|---|
[안드로이드] xml없이 layout, button, text 설정해보자! (0) | 2011.05.26 |
[안드로이드] tab line 없애기 tabStripEnabled (0) | 2011.05.24 |
[안드로이드] tab 높이 조절 (0) | 2011.05.24 |
[안드로이드] 인트로 화면 구성하기 (0) | 2011.05.24 |