Android Progress bar on ImageView

后端 未结 2 401
情话喂你
情话喂你 2021-01-31 20:53

I am developing an app in which user will take Picture from camera and display it on preview screen having image view.

**CameraCapture.java**

class ButtonClickH         


        
相关标签:
2条回答
  • 2021-01-31 21:19

    Put your ImageView and Progressbar in a RelativeLayout. For your ProgressBar, use:

    android:layout_centerInParent="true"
    

    Which will center it in the RelativeLayout, meaning over the ImageView. You might also want to hide the ProgressBar when the image has loaded:

    progressBar.setVisibility(View.Gone)
    

    when the image has been loaded.

    Sample code:

     <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
    
             <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"/>
    
            <ProgressBar
                style="?android:attr/progressBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:visibility="visible"/>
    
        </RelativeLayout>
    
    0 讨论(0)
  • 2021-01-31 21:41

    This is my solution. It is a little bit different. You can use it to create intro view with an image and progress bar. Here, progress bar is at 150dp to the bottom of center. FrameLayout can also be used.

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/intro_description"
            android:scaleType="fitXY"
            android:src="@drawable/intro" />
    
        <ProgressBar
            android:id="@+id/progress"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="150dp"
            android:visibility="visible" />
    
    </FrameLayout>
    
    0 讨论(0)
提交回复
热议问题