PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 17, 2022

[FIXED] How to make a ProgressBar stay in the center of screen despite scrolling

 November 17, 2022     android, vertical-alignment     No comments   

Issue

I have a ProgressBar in a ScrollView, and I'd like it to stay centered vertically despite the user scrolling down or up. However, I'm not sure how to accomplish this.

Here's the code that I have, simple as it is. I have an indeterminate ProgressBar:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ocr_scroll_view"
android:layout_width="match_parent"
android:layout_height="fill_parent">

    <RelativeLayout android:id="@+id/image_holder"
    android:layout_gravity="end"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

        <ImageView android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

        <ProgressBar android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:visibility="gone"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

And I call it as such:

    spinningProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
    spinningProgressBar.setIndeterminate(true);
    spinningProgressBar.setVisibility(View.GONE);

Setting its visibility at the appropriate times.

All suggestions very much appreciated.


Solution

Put it outside of the ScrollView. Just have the ScrollView and the ProgressBar overlap.

You can read about how to overlap views here: Overlapping Views in Android

There's a couple of ways to do it, ranging from GridLayouts to RelativeLayouts and then programatic ways to do it.



Answered By - Alex K
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing