I am using following code, but my progress bar is not displaying in the center of frame layout. I want to avoid padding to my progressbar.Can any one please explain? It is perfectly working if i am using "Linear Layout"
<?xml version="1.0" encoding="UTF-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal"> <ProgressBar android:id="@+id/progress_bar" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/gallery_img" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </FrameLayout>
Just change your Layout as RelativeLayout and add android:layout_centerInParent="true" to your ProgressBar.
You can apply a centering to any View, including a Layout, by using the XML attribute android:layout_gravity". You probably want to give it the value "center". AFAIK, layout_gravity is only for LinearLayout, not for arbitrary layouts.
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.
In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.
In the layout xml for your progressBar set the android:layout_gravity
(instead of android:gravity
) to "center"
android:layout_gravity = "center"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With