与MapView具有相同相对布局的ProgressBar:除非MapView可见,否则不可见

时间:2017-07-10 16:17:04

标签: android google-maps

所以这就是问题所在。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:theme="@style/TransparentBar"
                android:fitsSystemWindows="true"
>


<com.google.android.gms.maps.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fullscreen_map"
        android:visibility="invisible"
/>
<ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="visible"
        android:id="@+id/spinnerprogress"
/>

</RelativeLayout>

这是我的布局。

在代码中,我加载了大量数据,当它加载时,我隐藏了ProgressBar(setVisibility(View.GONE))并显示了MapView(setVisibility(View.VISIBLE)

问题是,除非MapView为View.VISIBLE,否则不会显示ProgressBar。如果我不隐藏它,只要我将MapView设置为可见就会出现。

有人对正在发生的事情有任何建议吗?

回答setVisibility:

public void onDataUpdate(JSONObject data) {
    ... work on data....
    mv.setVisibility(View.VISIBLE);
    //progressBar.setVisibility(View.GONE);
} 

基本上就是这样。

查看初始化:

@Override
public void onCreate(Bundle b) {
    super.onCreate(b);

    setContentView(R.layout.fullscreen_map);
    //This is workaround to show at least anything to user while data is being loaded.
    pd = new ProgressDialog(this);

    pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    //However, loading spinner inside the ProgressDialog is invisible as well unless MapView is showing.
    pd.setTitle(R.string.map_is_loading);
    pd.show();
    pd.setCancelable(false);
    progressBar = (ProgressBar) findViewById(R.id.spinnerprogress);
    mv = (MapView) findViewById(R.id.fullscreen_map);
    mv.getMapAsync(this); //data will be loaded after getMapAsync()
    mv.onCreate(b);
    buildingLocation = new LatLng(
            getIntent().getExtras().getDouble("building_lat"),
            getIntent().getExtras().getDouble("building_lng")
    );
    polyline = getIntent().getExtras().getString("polyline");
    name = getIntent().getExtras().getString("building_name");
    address = getIntent().getExtras().getString("building_addr");


    getSupportActionBar().setTitle(name);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);


}

主题:

    <style name="TransparentBar" parent="AppTheme">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">#ba864c</item>
        <item name="colorPrimaryDark">@color/status_bar_color</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorBackground">@color/app_general_background</item>
        <item name="android:actionOverflowButtonStyle">@style/ActionButtonThing</item>
        <item name="android:colorControlNormal">@color/pink_app_color</item>

    </style>

0 个答案:

没有答案