Kiraged
Kiraged

Reputation: 519

ProgressBar not showing in layout

I'm trying to implement a spinning progressBar but it won't show up no matter what I try. This is the xml:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
tools:context="com.example.home.quoteapp.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="@color/background">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:background="@drawable/rectangle">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/search"
                android:layout_width="35dp"
                android:layout_height="35dp"
                android:layout_alignParentEnd="true"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="18dp"
                android:background="@drawable/ic_search_black_24dp"
                android:clickable="true"
                android:focusable="true"
                android:gravity="center" />

            <Button
                android:id="@+id/back_arrow_search"
                android:layout_width="35dp"
                android:layout_height="35dp"
                android:layout_marginTop="18dp"
                android:background="@drawable/ic_arrow_back_black_24dp"
                android:clickable="true"
                android:focusable="true"
                android:visibility="invisible" />

            <Button
                android:id="@+id/nav_button"
                android:layout_width="35dp"
                android:layout_height="35dp"
                android:layout_marginTop="18dp"
                android:background="@drawable/ic_more_vert_black_24dp"
                android:clickable="true"
                android:focusable="true" />

            <EditText
                android:id="@+id/section"
                android:layout_width="230dp"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="30dp"
                android:layout_toEndOf="@+id/nav_button"
                android:layout_toRightOf="@+id/nav_button"
                android:background="@android:color/transparent"
                android:clickable="false"
                android:ems="10"
                android:focusable="false"
                android:gravity="left"
                android:inputType="textMultiLine|textNoSuggestions"
                android:maxHeight="140dp"
                android:scrollbars="vertical"
                android:text="@string/section"
                android:textColor="@color/textColor"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/searchText"
                android:layout_width="230dp"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/section"
                android:layout_alignBottom="@+id/section"
                android:layout_alignStart="@+id/section"
                android:background="@drawable/underline"
                android:ems="10"
                android:hint="Search"
                android:imeOptions="actionSearch"
                android:inputType="textMultiLine|textNoSuggestions|text"
                android:maxHeight="140dp"
                android:textColor="@color/textColor"
                android:textColorHint="@color/textHint"
                android:textCursorDrawable="@null"
                android:textSize="20sp"
                android:visibility="invisible" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

    <RelativeLayout
        android:id="@+id/progressBarLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:visibility="visible" />
    </RelativeLayout>

    <GridView
        android:id="@+id/gridView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"
        android:layout_marginEnd="5dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="5dp"
        android:alwaysDrawnWithCache="true"
        android:clipChildren="true"
        android:columnWidth="90dp"
        android:gravity="center"
        android:horizontalSpacing="5dp"
        android:numColumns="auto_fit"
        android:padding="0dp"
        android:scrollingCache="true"
        android:smoothScrollbar="true"
        android:stretchMode="columnWidth"
        android:verticalSpacing="5dp"></GridView>

</android.support.design.widget.AppBarLayout>


<android.support.design.widget.NavigationView
    android:id="@+id/navView"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/headerColour"
    android:theme="@style/NavigationTheme"
    android:visibility="invisible"
    app:itemBackground="@drawable/nav_item_background"
    app:itemTextColor="@color/headerColourAccent"
    app:menu="@menu/menu">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:background="@color/headerColourAccent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:gravity="left"
            android:paddingLeft="15dp"
            android:paddingTop="15dp"
            android:text="Sections"
            android:textColor="@color/headerColour"
            android:textSize="30dp" />

    </LinearLayout>
</android.support.design.widget.NavigationView>


</android.support.v4.widget.DrawerLayout>

And this is what I call in the MainActivity for the progressBar.

private RelativeLayout progressBarLayout;

private ProgressBar progressBar


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    progressBarLayout = findViewById(R.id.progressBarLayout);
    progressBar = findViewById(R.id.progressBar);
    progressBar.getIndeterminateDrawable().setColorFilter(0xF09D00, PorterDuff.Mode.MULTIPLY);
}

And then I would make the progressBar go away by doing this

progressBarLayout.setVisibility(View.GONE);

But the progressBar is never shown and when I set the visiblity to gone on the progressBarLayout it does go away.

Upvotes: 0

Views: 871

Answers (2)

Developer
Developer

Reputation: 133

Add sizes like this in Your ProgressBar:

android:maxHeight="20dp"
android:maxWidth="20dp"
android:minHeight="20dp"
android:minWidth="20dp"

Upvotes: 0

user9591909
user9591909

Reputation:

The problem is in your layout hierarchy. I made some few changes. The root is now a RelativeLayout containing the DrawerLayout and the Progressbar is removed outside the DrawerLayout and is now inside the root layout down below the DrawerLayout. Also the AppBarLayout was taking the whole screens width and height, which I guess isn't what you want, so that was changed to since it was blocking the other views below it

Here is a working layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--Drawer related content below here-->

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="top">

                <Button
                    android:id="@+id/search"
                    android:layout_width="35dp"
                    android:layout_height="35dp"
                    android:layout_alignParentEnd="true"
                    android:layout_marginEnd="10dp"
                    android:layout_marginTop="18dp"
                    android:clickable="true"
                    android:focusable="true"
                    android:gravity="center" />

                <Button
                    android:id="@+id/back_arrow_search"
                    android:layout_width="35dp"
                    android:layout_height="35dp"
                    android:layout_marginTop="18dp"
                    android:clickable="true"
                    android:focusable="true"
                    android:visibility="invisible" />

                <Button
                    android:id="@+id/nav_button"
                    android:layout_width="35dp"
                    android:layout_height="35dp"
                    android:layout_marginTop="18dp"
                    android:clickable="true"
                    android:focusable="true" />

                <EditText
                    android:id="@+id/section"
                    android:layout_width="230dp"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="30dp"
                    android:layout_toEndOf="@+id/nav_button"
                    android:layout_toRightOf="@+id/nav_button"
                    android:background="@android:color/transparent"
                    android:clickable="false"
                    android:ems="10"
                    android:focusable="false"
                    android:gravity="left"
                    android:inputType="textMultiLine|textNoSuggestions"
                    android:maxHeight="140dp"
                    android:scrollbars="vertical"
                    android:textSize="20sp" />

                <EditText
                    android:id="@+id/searchText"
                    android:layout_width="230dp"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/section"
                    android:layout_alignBottom="@+id/section"
                    android:layout_alignStart="@+id/section"
                    android:ems="10"
                    android:hint="Search"
                    android:imeOptions="actionSearch"
                    android:inputType="textMultiLine|textNoSuggestions|text"
                    android:maxHeight="140dp"
                    android:textCursorDrawable="@null"
                    android:textSize="20sp"
                    android:visibility="invisible" />
            </RelativeLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>


    <FrameLayout
        android:id="@+id/progressBarLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridView
            android:id="@+id/gridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="5dp"
            android:layout_marginEnd="5dp"
            android:layout_marginStart="5dp"
            android:layout_marginTop="5dp"
            android:alwaysDrawnWithCache="true"
            android:clipChildren="true"
            android:columnWidth="90dp"
            android:gravity="center"
            android:horizontalSpacing="5dp"
            android:numColumns="auto_fit"
            android:padding="0dp"
            android:scrollingCache="true"
            android:smoothScrollbar="true"
            android:stretchMode="columnWidth"
            android:verticalSpacing="5dp" />
    </FrameLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navView"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:visibility="invisible">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="left"
                android:gravity="left"
                android:paddingLeft="15dp"
                android:paddingTop="15dp"
                android:text="Sections"
                android:textSize="30dp" />

        </LinearLayout>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

<ProgressBar
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_gravity="center"
    android:indeterminate="true" />

</RelativeLayout>

Upvotes: 2

Related Questions