こちらでタブを持ったActivityを別途用意して試してみたのですが、質問されているような現象が再現しませんでした。
質問の意図を取り違えているのでしょうか。
lang
1import android.support.v4.app.Fragment;
2import android.support.v4.app.FragmentManager;
3import android.support.v4.app.FragmentPagerAdapter;
4import android.support.v4.app.FragmentTabHost;
5import android.support.v4.view.ViewPager;
6import android.support.v7.app.ActionBarActivity;
7import android.os.Bundle;
8import android.view.*;
9import android.widget.TextView;
10
11public class SampleActivity extends ActionBarActivity {
12
13 @Override
14 protected void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 setContentView(R.layout.activity_sample);
17
18 final FragmentTabHost host = (FragmentTabHost)findViewById(android.R.id.tabhost);
19 host.setup(this, getSupportFragmentManager(), R.id.content);
20
21 host.addTab(host.newTabSpec("tab1").setIndicator("ViewPager"), ViewPagerFragment.class, null);
22 host.addTab(host.newTabSpec("tab2").setIndicator("sample"), Tab2Fragment.class, null);
23
24
25 }
26
27 /**
28 * ViewPagerを持つFragment
29 */
30 public static class ViewPagerFragment extends Fragment {
31 private ViewPager vp;
32 private TutorialPagerAdapter vpa;
33
34 public ViewPagerFragment() {}
35
36 @Override
37 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
38 this.vp = new ViewPager(getActivity());
39 vp.setId(R.id.sampleViewPager);
40 vpa = new TutorialPagerAdapter(getChildFragmentManager());
41 vp.setAdapter(vpa);
42
43 return this.vp;
44 }
45 }
46
47 /**
48 * ViewPagerFragment用のFragmentPagerAdapter実装
49 */
50 public static class TutorialPagerAdapter extends FragmentPagerAdapter {
51 public TutorialPagerAdapter(FragmentManager fm) {
52 super(fm);
53 }
54
55 @Override public Fragment getItem(int i) {
56 switch (i) {
57 case 0: return new TutorialOne();
58 case 1: return new TutorialTwo();
59 case 2: return new TutorialThree();
60 default: return null;
61 }
62 }
63
64 @Override public int getCount() {return 3;}
65 }
66
67
68 /* ---------------------------
69 * サンプルFragment
70 */
71 public abstract static class TutorialFragmentBase extends Fragment {
72 private final String name;
73 public TutorialFragmentBase(String name) {
74 this.name = name;
75 }
76
77 @Override
78 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
79 TextView view = new TextView(container.getContext());
80 view.setText(this.name);
81 return view;
82 }
83 }
84
85 public static class TutorialOne extends TutorialFragmentBase {public TutorialOne() {super("TutorialOne");}}
86 public static class TutorialTwo extends TutorialFragmentBase {public TutorialTwo() {super("TutorialTwo");}}
87 public static class TutorialThree extends TutorialFragmentBase {public TutorialThree() {super("TutorialThree");}}
88 public static class Tab2Fragment extends TutorialFragmentBase {public Tab2Fragment() {super("タブ2");}}
89
90}
res/layout/activity_sample.xml は以下のとおり。
lang
1<?xml version="1.0" encoding="utf-8"?>
2<android.support.v4.app.FragmentTabHost
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:id="@android:id/tabhost"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent">
7
8 <LinearLayout
9 android:orientation="vertical"
10 android:layout_width="match_parent"
11 android:layout_height="match_parent">
12
13 <TabWidget
14 android:id="@android:id/tabs"
15 android:orientation="horizontal"
16 android:layout_width="match_parent"
17 android:layout_height="wrap_content"
18 android:layout_weight="0"/>
19
20 <FrameLayout
21 android:id="@android:id/tabcontent"
22 android:layout_width="0dp"
23 android:layout_height="0dp"
24 android:layout_weight="0"/>
25
26 <FrameLayout
27 android:id="@+id/content"
28 android:layout_width="match_parent"
29 android:layout_height="0dp"
30 android:layout_weight="1"/>
31
32 </LinearLayout>
33</android.support.v4.app.FragmentTabHost>
res/values/ids.xml は以下のとおり。
lang
1<?xml version="1.0" encoding="utf-8"?>
2<resources>
3 <item name="sampleViewPager" type="id" />
4</resources>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/01/23 14:33
2015/01/24 08:02
2015/02/02 14:40