信息窗口中的水平回收者视图谷歌地图

时间:2017-12-13 17:12:39

标签: android google-maps google-maps-api-3

我有带标记的群集谷歌地图,现在当我点击标记信息窗口打开时。但我希望更改信息窗口位置向下,如果在一个地方有很多东西我想在水平回收视图中显示一个列表,并且在我点击映射后它应该消失。

我还添加,现在我有幻灯片标签,在一个标签中我有谷歌地图。

所以看起来应该是这样的:

enter image description here

一些代码: 这是幻灯片标签的活动:

public class SlideTabsActivity extends AppCompatActivity {

private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_slide_tabs);
    if(SearchObjectList.getSearchObjectList().isEmpty()){
        Toast.makeText(getApplicationContext(), "Nic nie zostalo wybrane, wroc do SLideTabsActivity class aby zrobic jakas operacje gdy pusta lista",Toast.LENGTH_LONG).show();
    }
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

}
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        switch (position){
            case 0:
                FirstSlideTab firstSlideTab = new FirstSlideTab();
                return  firstSlideTab;
            case 1:
                SecondSlideTab secondSlideTab = new SecondSlideTab();
                return  secondSlideTab;
            case 2:
                ThirdSlideTab thirdSlideTab = new ThirdSlideTab();
                return thirdSlideTab;
            default:
                return null;
        }
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 3;
    }
    @Override
    public CharSequence getPageTitle(int position) {
        switch (position){
            case 0:
                return "FIRST";
            case 1:
                return "SECOND";
            case 2:
                return "THIRD";
        }
        return  null;
    }
}

} 在SecondSlideTab我有谷歌地图和类负责谷歌地图中的群集。这是SecondSlideTab的xml文件:

<android.support.constraint.ConstraintLayout 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:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="kamilmilik.flatsearch.showresultactivity.SlideTabsActivity">

<com.google.android.gms.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ProgressBar
    android:id="@+id/progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    app:layout_constraintBottom_toBottomOf="@+id/mapView"
    app:layout_constraintEnd_toEndOf="@+id/mapView"
    app:layout_constraintStart_toStartOf="@+id/mapView"
    app:layout_constraintTop_toTopOf="@+id/mapView" />

<FrameLayout
    android:id="@+id/fram_info_content"
    android:layout_width="match_parent"
    android:clickable="true"
    android:layout_height="150dp"
    app:layout_constraintBottom_toBottomOf="@+id/mapView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
     />

我应该添加什么来获取此信息窗口?我需要片段还是其他什么?如何将其添加到我的幻灯片标签和我的谷歌地图视图?

1 个答案:

答案 0 :(得分:0)

我建议你创建一个RecyclerView并将其与父底部对齐。然后在您的谷歌地图标记中添加OnMarkerClickListener。检测到点击后,您可以向RecyclerView适配器提供与该标记相关联的内容。

此链接让您了解如何实施mapview。 How to use MapView in android using google map V2?

标记是在onMapReady(GoogleMap gm)回调中创建的。

要了解如何创建标记,请阅读:https://developers.google.com/maps/documentation/android-api/marker

单击标记时,可以切换回收器视图可见性。