【发布时间】:2014-03-20 09:30:17
【问题描述】:
我有一些示例 FragmentTabHost 项目。我做了一些我的项目所需的修改。 我的标签栏 xml (bottom_tabs.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="0dip"
android:layout_weight="1" />
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
oncreate() - FragmentActivity
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
Bundle b = new Bundle();
b.putString("key", "Simple");
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
Fragment1.class, b);
//
b = new Bundle();
b.putString("key", "Contacts");
mTabHost.addTab(mTabHost.newTabSpec("contacts")
.setIndicator("Contacts"), Fragment2.class, b);
b = new Bundle();
b.putString("key", "Custom");
mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
Fragment3.class, b);
Fragment3 类
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_3,
null);
Button b = (Button) root.findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Fragment f;
f = (Fragment) new Fragment4();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.realtabcontent, f);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
});
return root;
}
问题: **
1) 如果我在 Fragment3 中按下 goto1 按钮,它会重定向到 Fragment4。 没有问题
2) 然后我按tab,Fragment4的布局是重叠的 在所有屏幕中
3) 如果我按转到第二个选项卡按钮,如何重定向到 Fragment2 和 同时应突出显示第二个选项卡。
**
请为我提供最好的方法。
【问题讨论】:
-
您找到解决方案了吗?我也面临类似的问题
-
它的替代品是什么??
-
我刚刚使用了活动。每个活动屏幕都有我在此布局中提到的选项卡图标
-
您在每个屏幕上创建标签布局?
标签: android android-fragments fragment