我正在使用带有以下适配器的视图寻呼机
public class PagerAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragments=null;
private FragmentManager fragmentManager=null;
private Fragment mLeftFragment;
private Fragment mRightFragment;
String[] title={"Home","Worklist","AgencyHome"};
public PagerAdapter(FragmentManager fragmentManager,List<Fragment> fragments)
{
super(fragmentManager);
this.fragments=fragments;
this.fragmentManager=fragmentManager;
}
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object)
{
super.setPrimaryItem(container,0,object);
}
@Override
public void notifyDataSetChanged()
{
super.notifyDataSetChanged();
}
@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
fragmentManager.executePendingTransactions();
fragmentManager.saveFragmentInstanceState(fragments.get(position));
}
@Override
public CharSequence getPageTitle(int position)
{
return title[position];
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
在第一页我有地图。我想用列表视图替换地图,反之亦然。
地图布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map_fragment_root_id"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/Linearcategory" >
</com.google.android.gms.maps.MapView>
和列表视图布局是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_fragment_root_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:animateLayoutChanges="true"
android:orientation="vertical" >
<ListView
android:id="@+id/mapList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/switchtolist"
android:scrollbars="none"
>
</ListView>
问题是交易后mapview会出现在列表下面
交易代码是
FragmentTransaction trans = fragmentManager.beginTransaction();
trans.replace(R.id.map_fragment_root_id, listfragment);
trans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
trans.addToBackStack(null);
trans.commit();
请帮助我,因为我是 Fragment 和 viewpager 的新手。我过去一周一直在处理这个问题,但找不到解决方案。