1
나는 안드로이드에 초보자입니다. 나는 15 개의 탭을 보여주는 안드로이드 애플리케이션을 개발했다. 한 가지 문제는 각 탭의 제목을 완전히 볼 수 없다는 것입니다. 안드로이드의 탭은 스크롤 가능합니까? 아래 코드를 사용하여 탭을 만듭니다. 더 나은 솔루션안드로이드에 탭 제목을 완전히 표시하는 방법
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="wrap_content"
>
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="500px" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1">
<TextView android:text="Tab1 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2">
<TextView android:text="Tab2 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3">
<TextView android:text="Tab3 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab4">
<TextView android:text="Tab4 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab5">
<TextView android:text="Tab5 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab6">
<TextView android:text="Tab6 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab7">
<TextView android:text="Tab7 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab8">
<TextView android:text="Tab8 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab9">
<TextView android:text="Tab9 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab10">
<TextView android:text="Tab10 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab11">
<TextView android:text="Tab11 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab12">
<TextView android:text="Tab12 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab13">
<TextView android:text="Tab13 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab14">
<TextView android:text="Tab14 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab15">
<TextView android:text="Tab15 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
활동 클래스 찾고
package mtx.samples;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class NewTabAppActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final AlertDialog.Builder ad = new AlertDialog.Builder(this);
TabHost tabHost = getTabHost();
// tab1
TabSpec ts1 = tabHost.newTabSpec("Tab1");
ts1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.rss));
ts1.setContent(R.id.tab1);
tabHost.addTab(ts1);
// tab2
TabSpec ts2 = tabHost.newTabSpec("Tab2");
ts2.setIndicator("Tab 2");
ts2.setContent(R.id.tab2);
tabHost.addTab(ts2);
// tab3
TabSpec ts3 = tabHost.newTabSpec("Tab3");
ts3.setIndicator("Tab 3");
ts3.setContent(R.id.tab3);
tabHost.addTab(ts3);
// tab4
TabSpec ts4 = tabHost.newTabSpec("Tab4");
ts4.setIndicator("Tab 4");
ts4.setContent(R.id.tab4);
tabHost.addTab(ts4);
// tab5
TabSpec ts5 = tabHost.newTabSpec("Tab5");
ts5.setIndicator("Tab 5");
ts5.setContent(R.id.tab5);
tabHost.addTab(ts5);
// tab6
TabSpec ts6 = tabHost.newTabSpec("Tab6");
ts6.setIndicator("Tab 6");
ts6.setContent(R.id.tab6);
tabHost.addTab(ts6);
// tab7
TabSpec ts7 = tabHost.newTabSpec("Tab7");
ts7.setIndicator("Tab 7");
ts7.setContent(R.id.tab7);
tabHost.addTab(ts7);
// tab8
TabSpec ts8 = tabHost.newTabSpec("Tab8");
ts8.setIndicator("Tab 8");
ts8.setContent(R.id.tab8);
tabHost.addTab(ts8);
// tab9
TabSpec ts9 = tabHost.newTabSpec("Tab9");
ts9.setIndicator("Tab 9");
ts9.setContent(R.id.tab9);
tabHost.addTab(ts9);
// tab10
TabSpec ts10 = tabHost.newTabSpec("Tab10");
ts10.setIndicator("Tab 10");
ts10.setContent(R.id.tab10);
tabHost.addTab(ts10);
// tab11
TabSpec ts11 = tabHost.newTabSpec("Tab11");
ts11.setIndicator("Tab 11");
ts11.setContent(R.id.tab11);
tabHost.addTab(ts11);
// tab12
TabSpec ts12 = tabHost.newTabSpec("Tab12");
ts12.setIndicator("Tab 12");
ts12.setContent(R.id.tab12);
tabHost.addTab(ts12);
// tab13
TabSpec ts13 = tabHost.newTabSpec("Tab13");
ts13.setIndicator("Tab 13");
ts13.setContent(R.id.tab13);
tabHost.addTab(ts13);
// tab14
TabSpec ts14 = tabHost.newTabSpec("Tab14");
ts14.setIndicator("Tab 14");
ts14.setContent(R.id.tab14);
tabHost.addTab(ts14);
// tab15
TabSpec ts15 = tabHost.newTabSpec("Tab15");
ts15.setIndicator("Tab 15");
ts15.setContent(R.id.tab15);
tabHost.addTab(ts15);
ad.setTitle("NewTabApp");
ad.setNeutralButton("OK", null);
Button btnSendSettings = (Button)findViewById(R.id.btnSendSettings);
btnSendSettings.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Send Settings button Clicked");
ad.show();
}
});
Button btnClose = (Button)findViewById(R.id.btnClose);
btnClose.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
System.exit(-1);
}
});
Button btnSave = (Button)findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Save button Clicked");
ad.show();
}
});
Button btnSend = (Button)findViewById(R.id.btnSend);
btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Send button Clicked");
ad.show();
}
});
}
}