0

I'm trying to add a spinning progress visual for my Android app, and for the sake of making it complicated, I'm currently only starting it in my onCreate and not ending it, because it should be pretty simple to get that right. However, following the official Android docs for the Progress bar which specifies to simply include

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
/>

for an indeterminate loading bar, it doesn't work. I've tried adding indeterminate and visibility to it, but no luck.

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true"
    android:visibility="visible"
/>

I'm using Kotlin's android extensions, so in my onCreate() I've tried

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    //setVisibility here doesn't actually get shown as an option in the autocomplete, but still compiles.
    weather_loading_bar.setVisibility(View.VISIBLE)
}

but when my app starts up, there is no progress bar.

EDIT: Here is the entire activity_main layout

<RelativeLayout 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"
tools:context=".ui.MainActivity">

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/currentData"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardBackgroundColor="@color/blue"
    card_view:cardCornerRadius="0dp"
    card_view:cardMaxElevation="25dp">

    <RelativeLayout
        android:id="@+id/cardviewLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp">

        <LinearLayout
            android:id="@+id/temperature_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="10sp"
                tools:text="this is the time" />

            <TextView
                android:id="@+id/temperature"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp"
                tools:text="50°" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/feel_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Feels Like"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/feels"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp" />

        </LinearLayout>

        <!-- Layout Middle-->

        <LinearLayout
            android:id="@+id/forecast_summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="30dp">

            <ImageView
                android:id="@+id/current_icon"
                android:layout_width="100dp"
                android:layout_height="100dp" />

            <TextView
                android:id="@+id/summary_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="15sp" />
        </LinearLayout>

        <!-- End Layout Middle -->

        <!-- Layout bottom -->

        <LinearLayout
            android:id="@+id/precip_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/forecast_summary"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Chance of Rain"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/precipitation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/wind_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/forecast_summary"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Wind Speed"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/wind"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp" />
        </LinearLayout>

        <!-- End layout bottom -->

    </RelativeLayout>

</android.support.v7.widget.CardView>

<view
    android:id="@+id/recycler_view"
    class="android.support.v7.widget.RecyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/currentData"
    android:layout_centerInParent="true" />

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true"
    android:visibility="visible"
/>

Rafa
  • 3,219
  • 4
  • 38
  • 70
  • 1
    You will need to provide your entire activity_main.xml file to determine why the progress bar isn't displaying. – tim.paetz Oct 05 '17 at 15:15
  • This is most probably a problem with your layout, not Kotlin. – fweigl Oct 05 '17 at 15:15
  • I've gone ahead and made the edit for including the layout – Rafa Oct 05 '17 at 15:34
  • Your `ProgressBar` is at the most bottom of your layout. Read this [question](https://stackoverflow.com/questions/2614393/defining-z-order-of-views-of-relativelayout-in-android) to get further detail. – BakaWaii Oct 05 '17 at 15:39

2 Answers2

1

You have a few large issues with your layout. The first being, you are not specifying in the layout where your progress bar should show up. You need to add bounds to it in relation to the parent RelativeLayout.

The second is, RelativeLayout is an extension of FrameLayout, which stacks views from back to front. So, your progress bar is in the back of the layout, with the CardView (and everything in and on top of it) in front.

WoogieNoogie
  • 1,258
  • 1
  • 11
  • 21
  • I'm adding it at the bottom and including `android:gravity="center"` but with no luck. – Rafa Oct 05 '17 at 15:50
  • use android:layout_centerInParent="true" to place it in center of parent element. – Mike Oct 06 '17 at 08:14
-1

Place your

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true"
    android:visibility="visible"
/>

at the bottom of the RelativeLayout below recycler view.

Mike
  • 2,547
  • 3
  • 16
  • 30