这是我的活动,tab
在浏览布局时不会滚动,这是我的代码:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class ProgramInfoActivity extends ActionBarActivity implements android.support.v7.app.ActionBar.TabListener {
private static final String TAG = "STRING";
private ViewPager viewPager;
private ProgramTabsPagerAdapter mAdapter;
Intent intent;
Fragment fragment;
// Tab titles
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_program_info);
intent = getIntent();
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager1);
mAdapter = new ProgramTabsPagerAdapter(getSupportFragmentManager());
// fragment = new Fragment();
viewPager.setAdapter(mAdapter);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
// getSupportActionBar().setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setNavigationMode(android.support.v7.app.ActionBar.NAVIGATION_MODE_TABS);
actionBar.addTab(actionBar.newTab().setText("UnderGraduate").setIcon(R.drawable.ic_action_academic).setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("Graduate").setIcon(R.drawable.ic_action_ic_course).setTabListener(this));
actionBar.addTab(actionBar.newTab().setText("PostGraduate").setIcon(R.drawable.ic_action_academic).setTabListener(this));
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
getActionBar().setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
@Override
public void onTabSelected(android.support.v7.app.ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());
Log.v(TAG, "clicked");
if (tab.getPosition()==0) {
}
}
@Override
public void onTabUnselected(android.support.v7.app.ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
}
@Override
public void onTabReselected(android.support.v7.app.ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}
<<我的片段>>>
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// programInfo = (TextView) vg.findViewById(programinfo);
listView = (ListView) vg.findViewById(R.id.programinfo);
layoutInflater = getActivity().getLayoutInflater();
dbFields = new DbFields();
dbHelper = new DbHelper(this.getActivity());
readJsonProgram();
programAdapter = new ProgramAdapter(this,layoutInflater,programList);
listView.setAdapter(programAdapter);
}
答案 0 :(得分:0)
您必须在setOnPageChangeListener Mehtod中为onPageScrolled添加代码。
false