私はまだAndroidプログラミングにかなり慣れていないので、これは私が見落としている簡単なことかもしれません。
Android 4以降を対象としたアプリを作成しており、タブホストを実装しています。(アクションバーのタブでAndroid開発者ガイドを読みましたが、それでも理解できませんでした。)とにかく、タブを切り替える場合を除いて、すべてが正常に機能します。これを行うと、前のタブのコンテンツがまだ重複しています。たとえば、タブ1、2、3、ボタン1、2、3があります。ボタン1から3に切り替えると、それらは重なっています。
Fragment.java
public class fragment extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment);
TabHost th = (TabHost)findViewById(R.id.tabhost);
th.setup();
TabSpec ts = th.newTabSpec("tag1");
ts.setContent(R.id.tab1);
ts.setIndicator("Tab one");
th.addTab(ts);
ts.setContent(R.id.tab2);
ts.setIndicator("Tab two");
th.addTab(ts);
ts.setContent(R.id.tab3);
ts.setIndicator("Tab Three ");
th.addTab(ts);
}
}
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NUmber one" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number two"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NUmber three" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
どんな助けでもいただければ幸いです。