• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Full screen background behind ProgressBar & maintain aspect ratio

Newbie question, I'm trying to work out how to have a full screen background behind ProgressBar, and need background image to keep its aspect ratio. As I understand it it might not be possible to maintain aspect ratio with background image?

in activity_main.xml I have

Code:
        <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:background="@mipmap/splash"
            android:indeterminate="false"
            android:padding="120dp"
            android:textAlignment="center" />

in java/MainActivity show progressbar:

Code:
if (isNetworkStatusAvialable(getApplicationContext())) {
    mWebView.setWebViewClient(new com.myapp.webview.MyAppWebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            findViewById(R.id.progressBar1).setVisibility(View.VISIBLE);
        }

then hide when ready:

Code:
                @Override
                public void onPageFinished(WebView view, String url) {
                    //hide loading image
                    findViewById(R.id.progressBar1).setVisibility(View.GONE);
                    //show url in webview
                    findViewById(R.id.web_view).setVisibility(View.VISIBLE);
//Close loading
                    mySwipeRefreshLayout.setRefreshing(false);
                }
            });

It does the job except background image is just stretched to fit and doesn't always look great as it loses its aspect ratio.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones