Tabhost 和 android.support.v4.view.ViewPager如何整合
最近在做一个将tabhost 改成 tabcontent 部位可左右滑动的东西。使用了谷歌提供的android.support.v4 包里面的viewpager组件.
原理就是把tabhost 里原有的的tabcontent 隐藏掉,加一个viewpager,捕捉事件进而进行互相刷新的动作。
唯一有所不同的就是tabhost里的content是各个单独的Activity.
具体代码如下:
主窗口
Java code?1 package org.xzx; import android.app.Activity; import android.app.LocalActivityManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.View; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; import java.util.ArrayList; public class TestViewpageActivity extends Activity { Context context = null; LocalActivityManager manager = null; ViewPager pager = null; TabHost tabHost = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = TestViewpageActivity.this; manager = new LocalActivityManager(this, true); manager.dispatchCreate(savedInstanceState); tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup();
[1] [2] [3] [4] [5] [6] [7] [8] 下一页