음... 탭위젯을 짜는도중 전 분명히 코드를 100% 잘 짰는데, 갑자기 이상하게 출력이 되서요...
코드는 아래와 같습니다.
------------------------ Main.xml 코드 ----------
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageButton
android:id="@+id/android_button1"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/icon"
/>
<ImageButton
android:id="@+id/android_button2"
android:layout_toRightOf="@id/android_button1"
android:layout_alignTop="@id/android_button1"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/android" />
<ImageButton
android:id="@+id/android_button3"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/android" />
</LinearLayout>
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</TabHost>
---------------------------------------- 자바 코드------------------------
package my.MWMK001;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
public class MWMK001 extends TabActivity {
TabHost mTabHost = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
final ImageButton button = (ImageButton) findViewById(R.id.android_button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(MWMK001.this, "1번학생부터 10번학생은..", Toast.LENGTH_SHORT).show();
Toast.makeText(MWMK001.this, "1번 바니.", Toast.LENGTH_SHORT).show();
Toast.makeText(MWMK001.this, "2번 또또.", Toast.LENGTH_SHORT).show();
Toast.makeText(MWMK001.this, "3번 곰돌이.", Toast.LENGTH_SHORT).show();
}
});
final ImageButton button2 = (ImageButton) findViewById(R.id.android_button2);
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(MWMK001.this, "11번학생부터 20번학생은..", Toast.LENGTH_SHORT).show();
Toast.makeText(MWMK001.this, "11번 지영.", Toast.LENGTH_SHORT).show();
Toast.makeText(MWMK001.this, "12번 나나.", Toast.LENGTH_SHORT).show();
Toast.makeText(MWMK001.this, "13번 승리.", Toast.LENGTH_SHORT).show();
}
});
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
mTabHost.setCurrentTab(0);
}
}
------------------------------ 참고그림
도대체 이상하지 않습니까?? 어디가 이상한건가요??
으으... 2시간째에요 정말 머리에 쥐가나서 이젠 올바른 판단력도 서질않네요 .....이미지가 탭버튼 안에있는데... 저걸 어떻게 꺼내야하나요 ㅠㅠ.
탭위젯 바로 아래 FrameLayout을 사용하셨습니다.
프레임 레이아웃은 위치를 지정해주지 않으면 한자리에 겹쳐서 나오니깐...
각 버튼들에
android:layout_marginTop="50dip" 이나 android:paddingTop="50dip" 을 줘보시구요.
한큐에 주실려면 버튼을 감싸고 있는 리니어레이아웃에 위와같이 주시면 됩니당. ^^
착실이님감사합니다. 그런데, 다만 문제가 되는건, TAB1에만 ImageButton이 나와야하는데, TAB2와 TAB3에도 나오네요 ㅠ0ㅠ
어떻게 고쳐야할까요 ㅠ0ㅠ
음....제가 보기엔 탭에 버튼이 올라가 있는게 좀 이상하네요. ^^(물론 뜻이 있어서 그렇게 하신거겠지만요.)
만약에 탭에 아이콘을 넣고싶으신거였으면...
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
요 부분에 .set백그라운드였나 해서 아이콘 추가 하는게 있습니다.
(이클립스에서 작업하신다고 가정하면 mTabHost. 까지만 치면 메소드가 나올꺼에요)
그리고 버튼을 의도하신거라면...
이미지버튼2, 3에 android:layout_marginLeft="15dip" 나 android:paddingLeft="15dip" 와 같이 거리를 수동으로 벌려주세요.