谷歌地图没有完全显示在Android的TabFragment中

时间:2018-05-22 10:47:50

标签: android google-maps

我的应用程序中有两个标签,一个标签我有谷歌地图,它没有完全显示在牛轧糖和奥利奥手机。请帮我修复我的问题。正确的版本地图显示正确。我已附上我的截图。< / p>

标签代码:

public class SampleTab extends Fragment  {

    public SampleTab() {
        // Required empty public constructor
    }

    //This is our tablayout
    private TabLayout tabLayout;

    //This is our viewPager
    private ViewPager viewPager;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        final View view = inflater.inflate(R.layout.samtab, container, false);
        //Initializing the tablayout
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);

        //Adding the tabs using addTab() method
        tabLayout.addTab(tabLayout.newTab().setText("Your Tab Title"));
        tabLayout.addTab(tabLayout.newTab().setText("Your Tab Title"));
        tabLayout.addTab(tabLayout.newTab().setText("Your Tab Title"));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        //Initializing viewPager
        viewPager = (ViewPager)view. findViewById(R.id.pager);

        //Creating our pager adapter
        Pager adapter = new Pager(getFragmentManager(), tabLayout.getTabCount());

        //Adding adapter to pager
        viewPager.setAdapter(adapter);

        //Adding onTabSelectedListener to swipe views
        tabLayout.setOnTabSelectedListener(this);
        return view;
    }

地图代码:

public class MapFragment extends Fragment implements
        OnMapReadyCallback {
    private MapView gs_mapView;
    private final LatLng HAMBURG = new LatLng(53.558, 9.927);
    private final LatLng KIEL = new LatLng(53.551, 9.993);

    private static final String ARG_SECTION_NUMBER = "section_number";

    private GoogleMap mMap;
    private Marker marker;

    public MapFragment() {
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        final View view = inflater.inflate(R.layout.fragemnt_clockout, container, false);



        return view;
    };

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        gs_mapView = (MapView) view.findViewById(R.id.mapView);

        gs_mapView.onCreate(savedInstanceState);



        gs_mapView.getMapAsync(this);
    }

    @Override
    public void onResume() {
        super.onResume();

     }


    @Override
    public void onMapReady(GoogleMap googleMap) {
        // Log.d("MyMap", "onMapReady");
        MapsInitializer.initialize(this.getActivity());

        mMap = googleMap;
        setUpMap();
    }

    private void setUpMap() {

        if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {

            if (ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                    ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1002);
            }else {
                //This line will show your current location on Map with GPS dot
                mMap.setMyLocationEnabled(true);

            }
        }
        else {
            //This line will show your current location on Map with GPS dot
            mMap.setMyLocationEnabled(true);
        }


        mMap.setMyLocationEnabled(true);
        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        mMap.getUiSettings().setMapToolbarEnabled(false);

        Marker hamburg = mMap.addMarker(new MarkerOptions().position(HAMBURG)
                .title("Hamburg"));


        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        mMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }
}

enter image description here 请任何人帮我解决这个问题,我是否需要添加任何权限?我不知道如何解决,我尝试了很多我没有得到解决方案。

enter image description here xml .file

<RelativeLayout
    android:id="@+id/clockInDetaisPage"
    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"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <RelativeLayout
        android:visibility="visible"
        android:id="@+id/relay1"
        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:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/mapView" />


    </RelativeLayout>


</RelativeLayout>

我在我的Activity中调用Sample Fragment,Sample Fragment只包含标签代码。

如果我给MapFragment Separate意味着它正确显示,当我添加到标签时,我只面对这个问题。这也只是奥利奥和牛轧糖版本

0 个答案:

没有答案
相关问题