我正在使用一些Fragments,FragmentActivity,ViewPager ......我可以从一个片段滑动到另一个片段。在一个片段中,我有一个gmaps片段,我无法在其中导航,它将滑动到下一个/上一个片段。 我想知道是否有可能(我很确定它是!)来禁用gmap片段中的滑动。片段不是全屏,所以当我们在里面时,滑动可能会被禁用吗?
ViewPagerAdapter.java
public class ViewPagerAdapter extends FragmentPagerAdapter {
private Context _context;
public ViewPagerAdapter(Context context, FragmentManager fm) {
super(fm);
_context=context;
}
@Override
public Fragment getItem(int position) {
Fragment f = new Fragment();
switch(position){
case 0:
f=LayoutOne.newInstance(_context);
break;
case 1:
f=LayoutTwo.newInstance(_context);
break;
case 2:
f=LayoutTree.newInstance(_context);
break;
}
return f;
}
@Override
public int getCount() {
return 3;
}
}
ViewPagerStyle1Activity.java
public class ViewPagerStyle1Activity extends FragmentActivity {
private ViewPager _mViewPager;
private ViewPagerAdapter _adapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpView();
setTab();
}
private void setUpView(){
_mViewPager = (ViewPager) findViewById(R.id.viewPager);
_adapter = new ViewPagerAdapter(getApplicationContext(),getSupportFragmentManager());
_mViewPager.setAdapter(_adapter);
_mViewPager.setCurrentItem(0);
}
private void setTab(){
_mViewPager.setOnPageChangeListener(new OnPageChangeListener(){
@Override
public void onPageScrollStateChanged(int position) {}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {}
@Override
public void onPageSelected(int position) {
// TODO Auto-generated method stub
switch(position){
case 0:
findViewById(R.id.first_tab).setVisibility(View.VISIBLE);
findViewById(R.id.second_tab).setVisibility(View.INVISIBLE);
findViewById(R.id.third_tab).setVisibility(View.INVISIBLE);
break;
case 1:
findViewById(R.id.first_tab).setVisibility(View.INVISIBLE);
findViewById(R.id.second_tab).setVisibility(View.VISIBLE);
findViewById(R.id.third_tab).setVisibility(View.INVISIBLE);
break;
case 2:
findViewById(R.id.first_tab).setVisibility(View.INVISIBLE);
findViewById(R.id.second_tab).setVisibility(View.INVISIBLE);
findViewById(R.id.third_tab).setVisibility(View.VISIBLE);
break;
}
}
});
}
}
LayoutTree.java
public class LayoutTree extends Fragment {
private GoogleMap map;
public static Fragment newInstance(Context context) {
LayoutTree f = new LayoutTree();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.layout_tree, null);
map = ((SupportMapFragment ) getFragmentManager().findFragmentById(R.id.map)).getMap();
return root;
}
}
layout_tree.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:gravity="center|center"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:layout_width="290dp"
android:layout_height="465dp"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
提前谢谢!