gpt4 book ai didi

android - 如何隐藏 map fragment - Android

转载 作者:太空宇宙 更新时间:2023-11-03 11:43:16 31 4
gpt4 key购买 nike

使用下面的代码showhide MapFragment,效果很好:

public class MapFragmentActivity extends FragmentActivity {
...........
mMapFragment = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map));
googleMap = mMapFragment.getMap();
googleMap.setMyLocationEnabled(true);
.....
if(isChecked)
{
mMapFragment.getView().setVisibility(View.VISIBLE);
}
else
{
mMapFragment.getView().setVisibility(View.GONE);
}

但是每当我将它与Animation 一起使用时,Map 永远不会隐藏,它始终可见,而动画对我有用;

if(isChecked)
{
mMapFragment.getView().setVisibility(View.VISIBLE);
mMapFragment.getView().startAnimation(AnimationUtils.loadAnimation(MapFragmentActivity.this,
R.anim.slide_up));
}
else
{
mMapFragment.getView().setVisibility(View.GONE);
mMapFragment.getView().startAnimation(AnimationUtils.loadAnimation(MapFragmentActivity.this,
R.anim.slide_down));
}

最佳答案

你可以试试这个

      private GoogleMap mMap;
private SupportMapFragment mMapFragment;

if(isCheked) {
mMapFragment = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapFragment));
mMap = mMapFragment.getMap();

mMapFragment.getView().setVisibility(View.Visible);

}
else {
mMapFragment = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapFragment));
mMap = mMapFragment.getMap();

mMapFragment.getView().setVisibility(View.INVISIBLE);

}

或者简单的方法是:

    if(isCheked) {
getSupportFragmentManager().beginTransaction().show(mFragment).commit();

}
else {
getSupportFragmentManager().beginTransaction().hide(mFragment).commit();
}

尝试一下,如果有效请告诉我。

这是 Kotlin 中第一个方法的 fragment ...

val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment?.view?.visibility = View.GONE

关于android - 如何隐藏 map fragment - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28297648/

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