Изменить положение кнопки Mylocation - PullRequest
0 голосов
/ 18 февраля 2019

Мое приложение продолжает падать, как только я пытаюсь переместить Google Mypsation Button.Это мой код:

private void locationButton() {

    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);

    View locationButton = ((View) mapFragment.getView().findViewById( Integer.parseInt( "1" ) ).
            getParent()).findViewById( Integer.parseInt( "2" ) );
    if (locationButton != null && locationButton.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
        // location button is inside of RelativeLayout
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();

        // Align it to - parent BOTTOM|LEFT
        params.addRule( RelativeLayout.ALIGN_PARENT_TOP, 0 );
        params.addRule( RelativeLayout.ALIGN_PARENT_BOTTOM );

        // Update margins, set to 10dp
        final int margin = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 150,
                getResources().getDisplayMetrics() );
        params.setMargins( margin, margin, margin, margin );

        locationButton.setLayoutParams( params );
    }

}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){

        buildGoogleApiClient();

        mMap.setMyLocationEnabled(true);
        mMap.setOnMarkerDragListener(this);
        locationButton();


    }

}

Как только я вызываю функцию, которая должна изменить положение, приложение вылетает.Это почему?Как я могу решить мою проблему и изменить ее положение?

I решил проблему, просто изменив первую строку на:

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...