gpt4 book ai didi

java - 更改宽度时,Google maps v2 fragment View 会闪烁

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:04:32 25 4
gpt4 key购买 nike

我的应用程序包含 Google map v2 API fragment View 。单击按钮时,我想像这样从左到右更改它的宽度:Google map 半屏显示 --> Google map 全屏显示。

有效,但我在宽度转换期间在屏幕右侧看到奇怪的黑色区域。我读到这是谷歌的错误,他们为此发布了修复程序,但它只适用于 Android 4.1 版本。我使用的是 Android 4.0

我还检查了其他人提到的一些变通方法,但它们都专注于滚动等任务。没有人提到谷歌地图 View 宽度变化。

谁能帮帮我?

我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="510dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp" />

<ImageView
android:id="@+id/mapExpandButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="25dp"
android:layout_marginRight="510dp"
android:background="@drawable/map_expand" />

<ImageView
android:id="@+id/mapCloseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="25dp"
android:layout_marginLeft="15dp"
android:background="@drawable/map_close" />

谷歌地图初始化:

        mapFragment = (SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
map = mapFragment.getMap ();
map.getUiSettings().setRotateGesturesEnabled(false); // disable rotation
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(54.6873439, 25.2770559) , 16.0f)); // set initial position
map.getUiSettings().setZoomControlsEnabled(false);

点击“展开”按钮时,我会像这样展开谷歌地图:

ResizeWidthAnimation anim = new ResizeWidthAnimation(mapFragment.getView (), width);
anim.setDuration(400);
mapFragment.getView ().startAnimation(anim);

动画类:

 public class ResizeWidthAnimation extends Animation
{
private int mWidth;
private int mStartWidth;
private View mView;

public ResizeWidthAnimation(View view, int width)
{
mView = view;
mWidth = width;
mStartWidth = view.getWidth();
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
int newWidth = mStartWidth + (int) ((mWidth - mStartWidth) * interpolatedTime);

mView.getLayoutParams().width = newWidth;
mView.requestLayout();

}

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight)
{
super.initialize(width, height, parentWidth, parentHeight);
}

@Override
public boolean willChangeBounds()
{
return true;
}
}

最佳答案

我们通过在 map 顶部添加一个 View 并为该 View 宽度变化设置动画来解决这个问题。没有其他工作。

避免 Google map 闪烁错误的提示:

  1. 不要对包含 Google map fragment 的 fragment 进行“添加”或“替换”操作。相反,使用 fragment View 的显示/隐藏操作。当您使用这些操作时,这不会重新创建已经创建的 fragment 。例如:

    FragmentManager manager = getSupportFragmentManager();  
    FragmentTransaction ft1 = manager.beginTransaction();
    ft1.show (someFragment);
    ft1.hide (someFragment2);
    ft1.commit();
  2. 在应用执行期间,请勿尝试更改谷歌地图 fragment 维度参数(宽度、高度、边距等)。如果您需要一些谷歌地图动画、宽度更改等,请使用其他(附加) View 搜索解决方法。

关于java - 更改宽度时,Google maps v2 fragment View 会闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23294138/

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