0

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>

Umer Asif
  • 441
  • 1
  • 4
  • 15
  • Can you show a screenshot of what it looks like when you can't scroll vertically? Is it by any chance zoomed out all the way? – Daniel Nugent Feb 03 '16 at 01:01
  • This might be a possible duplicate of [SO-16974983](http://stackoverflow.com/questions/16974983/google-maps-api-v2-supportmapfragment-inside-scrollview-users-cannot-scroll-th/17317176#17317176). – gerardnimo Feb 03 '16 at 11:28
  • It's not in a scrollView bro. – Umer Asif Feb 03 '16 at 13:22
  • What's the point of calling `isScrollGesturesEnabled()`? It returns a boolean but you're not doing anything with the result. According to the docs, scroll gestures are enabled by default so I don't think that's a problem: https://developers.google.com/android/reference/com/google/android/gms/maps/UiSettings.html#setScrollGesturesEnabled(boolean) – AdamMc331 Feb 03 '16 at 13:39
  • @McAdam331 i added it to try if it worked but it didn't – Umer Asif Feb 03 '16 at 13:41
  • @UmerAsif Maybe try explicitly setting it, even though the docs say it's by defualt? Try adding `googlemap.getUiSettings().setScrollGesturesEnabled(true);` ? – AdamMc331 Feb 03 '16 at 13:42
  • 1
    @McAdam331 didn't work. – Umer Asif Feb 03 '16 at 14:07

0 Answers0