我希望将 TabWidget 放在底部,就像 iPhone 应用程序一样。
我知道这种布局违反了 Google 用户界面指南,但是我需要它。
所以,我在 Stackoverflow 上阅读了许多类似的帖子。 但是每个帖子都不能正常工作。
我想使用 FragmentTabhost,而不使用外部库(例如ActionBarsherlock)。
这是我的代码。
所以我尝试了另一种布局,像这样。
所以,我在 Stackoverflow 上阅读了许多类似的帖子。 但是每个帖子都不能正常工作。
我想使用 FragmentTabhost,而不使用外部库(例如ActionBarsherlock)。
这是我的代码。
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_above="@android:id/tabs" />
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@android:id/tabs" />
<TabWidget
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" />
</RelativeLayout>
以下是活动代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_top);
//set up FragmentTabhost
FragmentTabHost host = (FragmentTabHost)findViewById(R.id.tabhost);
host.setup(this,getSupportFragmentManager(),R.id.content);
//add tabspec
TabSpec tabSpec1 = host.newTabSpec("tab1");
Button btn1 = new Button(this);
btn1.setBackgroundResource(R.drawable.icon1);
tabSpec1.setIndicator(btn1);
Bundle bundle1 = new Bundle();
bundle1.putString("name", "tab1");
host.addTab(tabSpec1,SampleFragment.class,bundle1);
TabSpec tabSpec2 = host.newTabSpec("tab2");
Button btn2 = new Button(this);
btn2.setBackgroundResource(R.drawable.icon2);
tabSpec2.setIndicator(btn2);
Bundle bundle2 = new Bundle();
bundle2.putString("name", "tab2");
host.addTab(tabSpec2,SampleFragment1.class,bundle2);
}
所以我尝试了另一种布局,像这样。
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<TabWidget
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
请帮助我,
注意:最终我解决了这个问题。 这是SupportPackage的一个bug......
尝试这个: