在我的應用程序中,我有一個帶有tabwidget的tabhost,它有幾個標籤。 現在我需要一個選項卡,它可以在tabcontent中顯示一個時間表網格,允許向左和向右滑動以移動月份。但我需要選項卡留下修復程序,只有時間表滑動。導航類型(固定標籤+滑動)
導航類型(固定標籤+滑動)允許我嗎?據我所知,這個導航允許滑動,但標籤不會保持不變。
我需要什麼可能嗎? 感謝您的幫助和關注。
在我的應用程序中,我有一個帶有tabwidget的tabhost,它有幾個標籤。 現在我需要一個選項卡,它可以在tabcontent中顯示一個時間表網格,允許向左和向右滑動以移動月份。但我需要選項卡留下修復程序,只有時間表滑動。導航類型(固定標籤+滑動)
導航類型(固定標籤+滑動)允許我嗎?據我所知,這個導航允許滑動,但標籤不會保持不變。
我需要什麼可能嗎? 感謝您的幫助和關注。
我會說可能的,留在你的代碼在tabhost和tabwidget。
所以我會假設其中一個選項卡正在調用一個可能命名爲Schedule.class的Activity,默認情況下tabhost不允許任何刷卡來更改選項卡功能,這很好。
在你的計劃活動所以,你將使用ViewPager,我學會了如何使用它從這篇文章:http://thepseudocoder.wordpress.com/2011/10/05/android-page-swiping-using-viewpager/
這是很容易理解的。您可以嘗試使用它,希望我回答了你的問題
更新:下面是一個示例
Schedule.class
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.schedule);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
List<Fragment> fragments = new ArrayList<Fragment>();
fragments.add(Fragment.instantiate(this, Fragment1.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment2.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment3.class.getName()));
MyFragmentAdapter miscFragmentAdapter = new MyFragmentAdapter(getSupportFragmentManager(), fragments);
viewPager.setAdapter(miscFragmentAdapter);
}
MyFragmentAdapter.class
public class MyFragmentAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public MiscFragmentAdapter(FragmentManager fragmentManager, List<Fragment> fragments) {
super(fragmentManager);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
}
schedule.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Fragment1.class或Fragment2.class或Fragment3.class
public class Fragment1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
return null;
}
return (LinearLayout) inflater.inflate(R.layout.fragment1, container, false);
}
}
片段1是任何你想要的裏面一個簡單的佈局。
Hello Chor。感謝您的回覆。在選項卡上調用Schedule.class(FragmentActivity),並且此FragmentActivity負責滑動。但是有可能把fragmentActivity放在fragmentLayout中,每個tab的tabcontent負責?謝謝 – 2013-05-02 11:34:07
我不明白你對fragmentLayout的觀點,你在項目中使用了什麼?但據我所知,使用什麼父母佈局並不重要。你可以嘗試通過在你的項目中實現上面的代碼來開始測試,並看看它是如何產生的。 – 2013-05-02 11:48:57