我尝试在片段内添加选项卡。我可以添加,但特定选项卡的内容与选项卡重叠
MainFragmentActivity.java
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment fragment= new FragmentTab();
getSupportFragmentManager().beginTransaction().add(R.id.content_frame,fragment).commit();
}
}
活动_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
FragmentTab.java
public class FragmentTab extends Fragment {
public FragmentTab() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
FragmentTabHost mTabHost;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
// TODO Auto-generated method stub
View rootView = inflater.inflate(R.layout.fragment_tabs, container, false);
mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment A"),
FragmentA.class, null);
mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("Fragment B" ),
FragmentB.class, null);
return rootView;
}
}
片段_选项卡.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
FragmentA.java
public class FragmentB extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View rootView= inflater.inflate(R.layout.fragment_a, container,false);
return rootView;
}
}
片段_a.xml
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FragmentA" />
</LinearLayout>
FragmentB.java
public class FragmentB extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View rootView= inflater.inflate(R.layout.fragment_b, container,false);
return rootView;
}
}
片段_b.xml
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FragmentB" />
</LinearLayout>
截屏 :
![enter image description here](https://i.stack.imgur.com/EELsB.png)
任何建议的帮助都会有帮助,我想要选项卡标题下方的选项卡片段的内容。
片段的内容与选项卡标题重叠。我使用 FragmentTabHost 在片段中使用选项卡布局强文本请帮助我如何解决这个问题。我想要选项卡标题下方的选项卡片段的内容。