I have a SupportMapFragment which only scrolls horizontally not vertically.I tried searching online but everyone had problem with horizontal Scroll which is fine in my case. Any help would be appreciated. Map doesn't move verically.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ViewPager pager = (ViewPager) findViewById(R.id.pager);
SetupViewPager(pager);
TabLayout tab = (TabLayout) findViewById(R.id.tabs);
tab.setupWithViewPager(pager);
public void SetupViewPager(ViewPager pager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new Map(),"Map");
adapter.addFragment(new CustomAlarm(),"2nd Tab");
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
public void addFragment(Fragment fragment, String Title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(Title);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
pager.setAdapter(adapter);
}
Here is my Map Fragment.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_blank, container, false);
SupportMapFragment support = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map));
support.getMapAsync(this);
return v;
}
@Override
public void onMapReady(GoogleMap googleMap) {
setmap(googleMap);
}
public void setmap(final GoogleMap map) {
googlemap = map;
googlemap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googlemap.getUiSettings().setMyLocationButtonEnabled(true);
googlemap.setOnMapLongClickListener(this);
}
Here is my XML.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Map"
android:orientation="horizontal">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
/>
MainActivity.xml
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/whatever"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed"
style="@style/CustomTabTheme"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight ="1"
android:background="@android:color/white"
/>
</android.support.design.widget.AppBarLayout>