gpt4 book ai didi

android - SupportMapfragment 不填充父级

转载 作者:行者123 更新时间:2023-11-29 15:20:24 25 4
gpt4 key购买 nike

当我在运行时用 SupportMapFragment 替换容器时,它不会填充 Parent。它仅部分占据屏幕。

HomeActivity2.java

package com.example.mapdemo;

import com.meteraid.android.services.LocationService;

import android.location.Location;
import android.os.Bundle;
import android.view.Menu;
import android.view.ViewGroup.LayoutParams;


public class HomeActivity2 extends BaseActivity2 {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_activity2);

LocationService locationService=LocationService.getInstance(this);
Location location=locationService.getCurrentLocation();

GoogleMapFragment mapFragment=new GoogleMapFragment();


mapFragment.setCurrentLocation(location);



android.support.v4.app.FragmentTransaction fragmentTransaction=getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container,mapFragment);
fragmentTransaction.commit();


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home_activity2, menu);
return true;
}

}

GoogleMapFragment

package com.example.mapdemo;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;

import android.location.Location;

public class GoogleMapFragment extends SupportMapFragment {

private static View view;
private Location location;

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

view = super.onCreateView(inflater, container, savedInstanceState);


Toast.makeText(getActivity(), "kkd",Toast.LENGTH_LONG).show();
initMap(location);
return view;

}

public void setCurrentLocation(Location location) {
this.location = location;
}

public void initMap(Location location) {

GoogleMap map = getMap();

Log.e("Locationnnnnnnnnn", location+"");
CameraPosition currentLocation = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location
.getLongitude())).zoom(4f).bearing(0).tilt(0).build();

map.moveCamera(CameraUpdateFactory.newCameraPosition(currentLocation));

//map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

}

}

activity_home_activity2.xml

 <FrameLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/fragment_container"
android:background="#cccccc"
tools:context=".HomeActivity2">
</FrameLayout>

enter image description here

最佳答案

看起来你已经设置了填充。删除您的填充,重新构建您的应用并检查它是否有效。

关于android - SupportMapfragment 不填充父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18947706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com