- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在开发一个应用程序,该应用程序具有在 Google map 上将团队显示为标记的应用程序功能。
我能够将自己显示为在我移动时更新的标记,而其他人则显示为 fragment 上的标记。
问题是标记仅在我第一次访问 MapFragment 时显示。当我导航到另一个 fragment 并返回 map 时,我看到一张没有标记和缩放按钮的空 map 。
尝试 #3,请查看以前实现的历史记录,它们略有不同:
我的 fragment 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/incident_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
/>
<ProgressBar
android:id="@+id/incident_map_progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"/>
<!--<com.google.android.gms.maps.MapView
android:id="@+id/incident_map"
android:layout_width="match_parent"
android:layout_height="match_parent" />-->
</RelativeLayout>
我的 IncidentMapFragment 代码,现在已根据用户反馈进行更新。更新很少。我在 onResume() 上使用 onActivityCreated() 而不是 onPause() 我使用 onSaveInstanceState(),请参阅下面的更新代码
package com.xyz.fragments;
//i did not include imports
//Based on https://developers.google.com/maps/documentation/android-sdk/map-with-marker
public class IncidentMapFragment extends Fragment implements OnMapReadyCallback {
public static final String TAG = "IncidentMapFragment";
private static IncidentMapFragment incidentMapFragment = null;
public static IncidentMapFragment instance() {
if (incidentMapFragment==null)
{
incidentMapFragment = new IncidentMapFragment();
}
return incidentMapFragment;
}
private MapView mapView;
private static GoogleMap map;
private ProgressBar progressBar;
private SupportMapFragment mapFragment;
public static final int UPDATE_MY_CURRENT_LOCATION = 0;
public static final int UPDATE_MY_TEAMS_CURRENT_LOCATIONS = 1;
public static final int UPDATE_ALL_TEAMS_CURRENT_LOCATIONS = 2;
public static final int UPDATE_ALL_LOCATION_BASED_EVENTS = 3;
private static Context context;
private int MY_DEFINED_ACCESS_COARSE_LOCATION_CALLBACK_RESULT = 1;
private int MY_DEFINED_ACCESS_FINE_LOCATION_CALLBACK_RESULT = 2;
boolean flagCoarseLocation = false;
boolean flagFineLocation = false;
private WamsUnitVehicleUnitRelationshipDao vehicleUnitRelationshipDao = new WamsUnitVehicleUnitRelationshipDaoImpl();
private static WamsUnitVehicleUnitRelationship newVehicleUnitRelationship = null;
private static CameraPosition cp;
private static Bundle markersBundle = new Bundle();
private static Bundle saveStateBundle = new Bundle();
private boolean createdStateInDestroyView = false;
private static final String SAVED_BUNDLE_TAG = "IncidentMapFragment_SAVE_STATE";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.incident_map_fragment, container, false);
context = rootView.getContext();
progressBar = rootView.findViewById(R.id.incident_map_progress_bar);
try {
FragmentManager fm = getActivity().getSupportFragmentManager();
if (savedInstanceState == null) {
mapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.incident_map, mapFragment,TAG).commit();
}
else {
mapFragment = (SupportMapFragment) fm
.findFragmentByTag(TAG);
}
if (savedInstanceState!=null) {
saveStateBundle = savedInstanceState.getBundle(SAVED_BUNDLE_TAG);
//restore camera
cp = saveStateBundle.getParcelable("cp");
//restore bundle of markers
markersBundle = saveStateBundle.getParcelable("markersBundle");
if (cp!=null && markersBundle!=null)
{
reDrawMarkers(markersBundle);
}
}
} catch (Exception exc) {
Log.e(TAG, exc.getMessage());
exc.printStackTrace();
}
return rootView;
}
@Override
public void onActivityCreated(Bundle bundle) {
super.onActivityCreated(bundle);
Log.i(TAG,"onActivityCreated()");
newVehicleUnitRelationship = vehicleUnitRelationshipDao.getWamsUnitVehicleUnitRelationship(NgfrApp.getInstance().getUniqueDeviceId());
if (mapFragment!=null) {
mapFragment.getMapAsync(this);
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
Log.i(TAG,"onSaveInstanceState()");
outState.putBundle(SAVED_BUNDLE_TAG, saveState());
createdStateInDestroyView = false;
super.onSaveInstanceState(outState);
}
@Override
public void onDestroyView() {
super.onDestroyView();
saveStateBundle = saveState();
createdStateInDestroyView = true;
cp = null;
markersBundle = null;
}
private Bundle saveState() {
Bundle state = new Bundle();
state.putParcelable("cp", cp);
state.putParcelable("markersBundle", markersBundle);
return state;
}
/*Handler used by outside class such as MqttBroker.
1) UPDATE_MY_CURRENT_LOCATION. When my location service send a update location(lat,long) call updateMarkersOnMap() which creates a new AsyncTask to update teh display
2) UPDATE_MY_TEAMS_CURRENT_LOCATIONS. When the MQTT dservice gets new location(lat,long) call updateMarkersOnMap() which creates a new AsyncTask to update teh display
3) UPDATE_ALL_TEAMS_CURRENT_LOCATIONS, not implemented.
*/
public static final Handler updateIncidentMap = new Handler(Looper.getMainLooper()) {
public void handleMessage(Message msg) {
//if the context is null then the MapFragment & GoogleMap objects are NOT instantiated and updating the maps non-existant UI will cause exceptions, NPE, and crashes!
if (context != null) {
Location myCurrentLocation = null;
final int what = msg.what;
switch (what) {
case UPDATE_MY_CURRENT_LOCATION:
Log.i(TAG,"UPDATE_MY_CURRENT_LOCATION");
myCurrentLocation = (Location) msg.obj;
if (map != null) {
updateMarkersOnMap(map,markersBundle, myCurrentLocation.getLatitude(),myCurrentLocation.getLongitude(),newVehicleUnitRelationship.getWamsId(), newVehicleUnitRelationship.getVehicleUnitId());
}
break;
case UPDATE_MY_TEAMS_CURRENT_LOCATIONS:
Log.i(TAG,"UPDATE_MY_TEAMS_CURRENT_LOCATIONS");
if (map != null) {
WamsLocationMarker wamsLocationMarker = (WamsLocationMarker) msg.obj;
updateMarkersOnMap(map, markersBundle,wamsLocationMarker.getLat(),wamsLocationMarker.getLon(), wamsLocationMarker.getClientId(), wamsLocationMarker.getVehicleId());
//mock team
mockTeam(map,markersBundle, wamsLocationMarker.getLat(),wamsLocationMarker.getLon());
}
break;
case UPDATE_ALL_TEAMS_CURRENT_LOCATIONS:
break;
default:
break;
}
} //end if context is NOt null
} //end handleMessage
};
/*I added the @SuppressLint("MissingPermission") because we are handling this in permissionHelper(getActivity()),
and the IDE is too naive to know*/
@SuppressLint("MissingPermission")
@Override
public void onMapReady(GoogleMap googleMap) {
Log.i(TAG, "onMapReady()");
try {
//remove progress bar
progressBar.setVisibility(GONE);
//initially zoom in my location
map = googleMap;
if (permissionHelper(getActivity()))
{
map.setMyLocationEnabled(true);
map.getUiSettings().setZoomControlsEnabled(true);
map.getUiSettings().setCompassEnabled(true);
}
if (cp != null) {
map.moveCamera(CameraUpdateFactory.newCameraPosition(cp));
cp = null;
}
reDrawMarkers(markersBundle);
}
catch (NullPointerException exc)
{
exc.printStackTrace();
}
}
private static void updateMarkersOnMap(GoogleMap map,Bundle bundle, double lat,double log, String id, String vehicleId) {
final GoogleMap _map = map;
final double _lat = lat;
final double _log = log;
final String _id = id;
final String _vehicleId = vehicleId;
new AsyncTask < Void, Void, WamsLocationMarker > () {
boolean update = false;
@Override
protected WamsLocationMarker doInBackground(Void...voids) {
Marker marker = null;
WamsLocationMarker wamsLocationMarker=null;
try {
Log.i(TAG,"async map: "+map);
if (_map != null && bundle!=null)
{
Log.i(TAG,_map.toString());
//if the wamsLocationMarker exists, then UPDATE
if (bundle.containsKey(_id)) {
Log.i(TAG,"markersBundle.containsKey(_id): "+ bundle.containsKey(_id));
Log.i(TAG,"update true");
//get from hashmap
wamsLocationMarker = (WamsLocationMarker)bundle.get(_id);
update = true;
} else {
//add to map
//if the ids are equal then this is YOU
wamsLocationMarker = new WamsLocationMarkerFactory().createWamsLocationMarker(_id, _vehicleId, _lat, _log);
Log.i(TAG,"WamsLocationMarker");
Log.i(TAG,"update false");
}
} else {
Log.e(TAG, " updateMarkersOnMap() map is " + _map);
}
}
catch (NullPointerException exc)
{
exc.printStackTrace();
}
return wamsLocationMarker;
}
@Override
protected void onPostExecute(WamsLocationMarker wamsLocationMarker) {
super.onPostExecute(wamsLocationMarker);
try {
if (wamsLocationMarker != null) {
Log.i(TAG,"onPostExecute() update:"+update+",wamsLocationMarker:"+wamsLocationMarker);
if (update) {
Log.i(TAG,"onPostExecute() update:"+update);
//UPDATE wth new lat & long if the markers coordinates have change, else dont redraw, beacuse the draw causes a refresh affect & its also a waste computationally
if (wamsLocationMarker.getMarker().getPosition().latitude != _lat && wamsLocationMarker.getMarker().getPosition().longitude != _log) {
LatLng latLng = new LatLng(_lat, _log);
//UPDATE THE MARKER POSITION
wamsLocationMarker.getMarker().setPosition(latLng);
}
} else {
//ADD A NEW MARKER
Marker marker = _map.addMarker(wamsLocationMarker.getMakerOptions());
Log.i(TAG,"ASYNC MARKER:"+marker.getId());
wamsLocationMarker.setMarker(marker);
markersBundle.remove(wamsLocationMarker.getClientId());
markersBundle.putParcelable(wamsLocationMarker.getClientId(), wamsLocationMarker);
}
}
}
catch (NullPointerException exc)
{
exc.printStackTrace();
}
}
}.execute();
}
public void reDrawMarkers(Bundle bundle) {
Log.i(TAG,"reDrawMarkers()");
if (bundle!=null) {
Set<String> keys = bundle.keySet();
WamsLocationMarker wamsLocationMarker = null;
for (String k : keys) {
Log.i(TAG, "key:" + k);
wamsLocationMarker = (WamsLocationMarker) bundle.getParcelable(k);
updateMarkersOnMap(map, bundle, wamsLocationMarker.getLat(), wamsLocationMarker.getLon(), wamsLocationMarker.getClientId(), wamsLocationMarker.getVehicleId());
}
}
}
//Just for test - Im mocking some there points to represent other teams mates on the map, this is just for testing
private static void mockTeam(GoogleMap map, Bundle bundle, double _lat, double _log) {
updateMarkersOnMap(map,bundle, _lat+0.001, _log , "mock111111111", newVehicleUnitRelationship.getVehicleUnitId());
updateMarkersOnMap(map,bundle,_lat, _log+0.001 ,"mock222222222", newVehicleUnitRelationship.getVehicleUnitId());
updateMarkersOnMap(map,bundle, _lat-0.001, _log,"mock33333333", newVehicleUnitRelationship.getVehicleUnitId());
updateMarkersOnMap(map,bundle, _lat, _log-0.001,"mock444444444", newVehicleUnitRelationship.getVehicleUnitId());
}
//Ask the user if required & attempt to grant required location services
private boolean permissionHelper(Activity activity) {
String permission = Manifest.permission.ACCESS_COARSE_LOCATION;
int res = getContext().checkCallingPermission(permission);
//if the required coarse & fine permissions are granted then return true else proceed to get the permissions
if (res == PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "ACCESS_COARSE_LOCATION GRANTED");
permission = Manifest.permission.ACCESS_FINE_LOCATION;
res = getContext().checkCallingPermission(permission);
if (res == PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "ACCESS_FINE_LOCATION GRANTED");
flagFineLocation = true;
} else {
Log.i(TAG, "ACCESS_FINE_LOCATION NOT GRANTED");
}
flagCoarseLocation = true;
}
//prompt user for COARSE location permission. If the user cancel then display toast & navigate back
if (!flagCoarseLocation) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.ACCESS_COARSE_LOCATION)) {
dialogForCoarsePermission();
} else {
ActivityCompat.requestPermissions(activity,
new String[] {
Manifest.permission.ACCESS_COARSE_LOCATION
},
MY_DEFINED_ACCESS_COARSE_LOCATION_CALLBACK_RESULT);
flagCoarseLocation = true;
}
}
//prompt user for FINE location permission. If the user cancel then display toast & navigate back
if (!flagFineLocation) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.ACCESS_FINE_LOCATION)) {
dialogForFinePermission();
} else {
ActivityCompat.requestPermissions(activity,
new String[] {
Manifest.permission.ACCESS_COARSE_LOCATION
},
MY_DEFINED_ACCESS_FINE_LOCATION_CALLBACK_RESULT);
flagFineLocation = true;
}
}
if (!flagCoarseLocation)
{
Log.i(TAG, "ACCESS_COARSE_LOCATION NOT GRANTED");
}
else
{
Log.i(TAG, "ACCESS_COARSE_LOCATION GRANTED");
}
if (!flagFineLocation)
{
Log.i(TAG, "ACCESS_FINE_LOCATION NOT GRANTED");
}
else
{
Log.i(TAG, "ACCESS_FINE_LOCATION GRANTED");
}
return (flagCoarseLocation && flagFineLocation);
}
private void dialogForCoarsePermission() {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
ActivityCompat.requestPermissions(getActivity(),
new String[] {
Manifest.permission.ACCESS_COARSE_LOCATION
},
MY_DEFINED_ACCESS_COARSE_LOCATION_CALLBACK_RESULT);
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("The map requires coarse location permission.Please it by pressing Yes. ").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
}
private void dialogForFinePermission() {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
ActivityCompat.requestPermissions(getActivity(),
new String[] {
Manifest.permission.ACCESS_FINE_LOCATION
},
MY_DEFINED_ACCESS_FINE_LOCATION_CALLBACK_RESULT);
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("The map ALSO requires fine location permission.Please it by pressing Yes. ").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
Log.i(TAG, "onRequestPermissionsResult() request code:" + requestCode); // Log printed
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == MY_DEFINED_ACCESS_COARSE_LOCATION_CALLBACK_RESULT) {
flagCoarseLocation = true;
Toast.makeText(context, "Coarse location permission granted.", Toast.LENGTH_SHORT).show();
}
if (requestCode == MY_DEFINED_ACCESS_FINE_LOCATION_CALLBACK_RESULT) {
flagFineLocation = true;
Toast.makeText(context, "Fine location permission granted.", Toast.LENGTH_SHORT).show();
}
}
}
我仅为该 fragment 提供了 GUI 和相应的日志。
我第一次导航到 fragment 。一切正常,您会看到转到我的位置按钮和缩放按钮:
现在,当我导航到名为“服务”的第一个 fragment 或将应用程序留在后台一段时间时,问题就会出现。我再也看不到标记了,并且添加了通过网络更新的新位置,但是没有绘制。 map 缩放按钮也不见了!!!
08-16 08:06:03.358 1314-1314/com.xyz I/IncidentMapFragment: onSaveInstanceState()
08-16 08:06:03.836 1314-1314/com.xyz I/IncidentMapFragment: reDrawMarkers()
key:015140000100161
key:mock33333333
key:mock444444444
key:mock111111111
key:mock222222222
08-16 08:06:03.836 1314-1340/com.xyz I/IncidentMapFragment: async map: com.google.android.gms.maps.GoogleMap@1e72e3b
com.google.android.gms.maps.GoogleMap@1e72e3b
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@1e72e3b
com.google.android.gms.maps.GoogleMap@1e72e3b
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@1e72e3b
com.google.android.gms.maps.GoogleMap@1e72e3b
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@1e72e3b
com.google.android.gms.maps.GoogleMap@1e72e3b
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@1e72e3b
com.google.android.gms.maps.GoogleMap@1e72e3b
markersBundle.containsKey(_id): true
update true
08-16 08:06:03.837 1314-1314/com.xyz I/IncidentMapFragment: onActivityCreated()
08-16 08:06:03.851 1314-1314/com.xyz I/IncidentMapFragment: onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@19b04df
onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@47c13e2
onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@6b22ea9
onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@e387818
08-16 08:06:03.852 1314-1314/com.xyz I/IncidentMapFragment: onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@dab0d7
onPostExecute() update:true
onMapReady()
ACCESS_COARSE_LOCATION GRANTED
ACCESS_FINE_LOCATION GRANTED
08-16 08:06:03.853 1314-1314/com.xyz I/IncidentMapFragment: reDrawMarkers()
08-16 08:06:03.854 1314-1314/com.xyz I/IncidentMapFragment: key:015140000100161
key:mock33333333
key:mock444444444
key:mock111111111
key:mock222222222
08-16 08:06:03.854 1314-1338/com.xyz I/IncidentMapFragment: async map: com.google.android.gms.maps.GoogleMap@b7d1933
com.google.android.gms.maps.GoogleMap@b7d1933
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@b7d1933
com.google.android.gms.maps.GoogleMap@b7d1933
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@b7d1933
com.google.android.gms.maps.GoogleMap@b7d1933
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@b7d1933
com.google.android.gms.maps.GoogleMap@b7d1933
markersBundle.containsKey(_id): true
update true
async map: com.google.android.gms.maps.GoogleMap@b7d1933
com.google.android.gms.maps.GoogleMap@b7d1933
markersBundle.containsKey(_id): true
update true
08-16 08:06:03.865 1314-1314/com.xyz I/IncidentMapFragment: onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@19b04df
onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@47c13e2
onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@6b22ea9
onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@e387818
onPostExecute() update:true
onPostExecute() update:true,wamsLocationMarker:com.xyz.mapping.WamsLocationMarker@dab0d7
onPostExecute() update:true
查看调试窗口:状态已恢复但未绘制 我的日志显示正在再次添加标记,没有错误或异常,但没有显示?** 为什么?我该如何解决这个问题?
谢谢
最佳答案
Obviously the 1st fragment is calling onResume(),onMapReady(),onPause(), which is resetting the map
您可能处理不当,因此我仍然认为问题仍然与 Activity/Fragment 状态更改有关。
查看是否是由于 fragment 状态变化引起的一个简单调整是在用户放置标记时将所有值存储到 SharedPreference,并在每次状态变化(onPause、onResume 等)时将它们分配给 map ).
对于 fragment 状态变化的解释
不同的事件,一些是用户触发的,一些是系统触发的,可以导致 Activity/Fragment 从一种状态转换到另一种状态,并重置 Activity/Fragment。因此,在 android 中,您需要处理 Activity 和 fragment 的不同状态。
对于处理 Activity 状态变化,您可以引用Android doc .
针对您的情况:
关于如何handle Fragment State Change 有一个非常好的示例和详细信息.
希望对您有所帮助!
关于Android MapFragment,无法在 map 上绘制并且无法恢复以前的 map 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51803267/
我学习 SDL 二维编程已有一段时间了,现在我想创建一个结合使用 SDL 和 OpenGL 的程序。我是这样设置的: SDL_Init(SDL_INIT_VIDEO); window = SDL_Cr
尝试查找可在地块中使用的不同类型项目的列表 来自不同样本的投影类型: projection = list(type = "equirectangular") projection = list(typ
我正在尝试使用 Java Graphics API 绘制 GIF,但无法使用下面的代码成功绘制 GIF。仅绘制 GIF 的第一张图像或缩略图,但不播放。 public void paintCompon
我目前正在使用 JFrame 并尝试绘制一个矩形,但我不知道如何执行代码 paint(Graphics g),如何获取 Graphics 对象? package com.raggaer.frame;
这个领域的新手,希望得到一些帮助。 我有一个"Missile.java" 类,我在那里画东西。我想绘制一个 ImageView,我正在使用以下代码: ImageView v = (ImageView)
下面列出了圆形的例子 这是我的 JavaScript 代码。 最佳答案 假设您的 randomColor 是正确的,您只需要: 从 canvas.onclick 中移除 context.clearR
我在绘制和缩放 ImageView 时遇到问题。请帮帮我.. 当我画一些东西然后拖动或缩放图像时 - 绘图保留在原处,如您在屏幕截图中所见。而且我只需要简单地在图片上绘图,并且可以缩放和拖动这张图片。
我们可以在形式之外绘制图像和文本...我的意思是在字面上... 我知道问这个问题很愚蠢但是我们能不能... 最佳答案 您可以通过创建表单并将其 TransparentColor 属性设置为背景色来“作
我在绘制/布局期间收到 3 个对象分配警告 super.onDraw(canvas); canvas.drawColor(Color.WHITE); Paint textPaint = new Pai
我有一个示例时间序列数据框: df = pd.DataFrame({'year':'1990','1991','1992','1993','1994','1995','1996',
我试图想出一种简洁的方法来绘制 R 数据框中所有列的 GridView 。问题是我的数据框中既有离散值又有数值。为简单起见,我们可以使用 R 提供的名为 iris 的示例数据集。我会使用 par(mf
我有一个由 10 列和 50 行组成的 data.frame。我使用 apply 函数逐列计算密度函数。现在我想绘制我一次计算的密度。 换句话说,而不是绘图... plot(den[[1]]) plo
我想知道我们如何才能在第一个和第二个组件之外绘制个人,如下所示: 最佳答案 这可能有效: pc.cr <- princomp(USArrests, cor = TRUE) pairs(pc.cr$lo
我是Pandas和matplotlib的新手,想绘制此DataFrame season won team matches pct_won 0 20
我正在尝试为 distplot 子图编写一个 for 循环。 我有一个包含许多不同长度列的数据框。 (不包括 NaN 值) fig = make_subplots( rows=len(asse
我想创建一个具有密度的 3d 图。 我使用函数 density 首先为特定的 x 值创建一个二维图,然后该函数创建密度并将它们放入 y 变量中。现在我有第二组 x 值并将其再次放入密度函数中,然后我得
全部, 我一直在研究全局所有 MTB 步道的索引。我是 Python 人,所以对于所有涉及的步骤,我都尝试使用 Python 模块。 我能够像这样从 OSM 立交桥 API 中获取关系: from O
我正在使用 e1071 包中的支持向量机对我的数据进行分类,并希望可视化机器实际如何进行分类。但是,在使用 plot.svm 函数时,出现无法解决的错误。 脚本: library("e1071") d
我制作了以下图表,它是使用 xts 对象创建的。 我使用的代码很简单 plot(graphTS1$CCLL, type = "l", las = 2, ylab = "(c)\nCC for I
在绘制状态图时,您如何知道哪些状态放在框中,哪些状态用于转换箭头?我注意到转换也是状态。 我正在查看 this page 上的图 1 : 最佳答案 转换不是状态。转换是将对象从一种状态移动到下一种状态
我是一名优秀的程序员,十分优秀!