Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set ProgressBar at the center screen in frame layout?

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> 
like image 861
Arslan Anwar Avatar asked Nov 30 '10 08:11

Arslan Anwar


People also ask

How do I center my progress bar?

Just change your Layout as RelativeLayout and add android:layout_centerInParent="true" to your ProgressBar.

How do you center a view?

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.

Which Layout is designed to block out an area on the screen?

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.

Which attribute is used to display ProgressBar horizontally?

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.


1 Answers

In the layout xml for your progressBar set the android:layout_gravity (instead of android:gravity) to "center"

android:layout_gravity = "center" 
like image 121
Piyush Avatar answered Sep 29 '22 11:09

Piyush