Android:片段中的表格滑动太过分了

时间:2015-06-09 18:17:42

标签: android eclipse android-fragments tabs swipe-gesture

这是我的问题:我的活动有3个标签,带有相对片段。第一个片段包含一个滑动照片查看器。为什么当我到达第一个片段的图片的末尾时,它会跳转到其他标签?我做错了什么或有没有办法停止刷到第一个片段的图片?这是我的代码。

主要活动

public class Home extends FragmentActivity implements ActionBar.TabListener {

private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;


private String[] tabs = { "Panoramica", "Contesto", "Storia" };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        

    // Adding Tabs
    for (String tab_name : tabs)
    {
        actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case R.id.table:
             startActivity(new Intent("android.intent.action.Home"));
            return true;
        case R.id.action_search2:
             startActivity(new Intent("android.intent.action.Reperti"));
            return true;
        case R.id.action_search3:
             startActivity(new Intent("android.intent.action.Sito"));
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
} [ --- Other Methods ---]

FirstFragment

    public class panoramica extends Fragment {

   @Override
   public View onCreateView(LayoutInflater inflater, ViewGroup container,
           Bundle savedInstanceState) {    


       View rootView = inflater.inflate(R.layout.fragment_panoramica, container, false);
       ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.pager);
       PagerAdapter adapter = new ImageAdapter(getActivity());
       viewPager.setAdapter(adapter);           
       return rootView;
   }

}

这是我的适配器的一部分

public class ImageAdapter extends PagerAdapter{

    Context context;
    int[] imageId = {R.drawable.icon,R.drawable.home};

   [--- Other Methods---]

 public Object instantiateItem(ViewGroup container, int position) {
        // TODO Auto-generated method stub

        LayoutInflater inflater = ((Activity)context).getLayoutInflater();

        View viewItem = inflater.inflate(R.layout.fragment_foto, container, false);
        ImageView imageView = (ImageView) viewItem.findViewById(R.id.img);
        imageView.setImageResource(imageId[position]);
        ((ViewPager)container).addView(viewItem);

        return viewItem;
    }

}

1 个答案:

答案 0 :(得分:0)

将自定义视图寻呼机用于三个选项卡,其中禁用滑动。 你可以在这里找到例子: Is it possible to disable scrolling on a ViewPager