user5520878
user5520878

Reputation:

Progress bar is not center when under relative layout

I am using relative layout in my android app.

Following is my main.xml.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="fill"
    tools:context="com.example.asdf.MainActivity" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:scaleType="fitXY"
        android:src="@drawable/bgg" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="22dp"
        android:layout_marginTop="22dp"
        android:gravity="center"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:text=" Factualnote is an web annotation application, which helps the users to mark the specific text, element, page, video, etc in a web page and share it to like-minded people.\r\n \r\nAs we know the relevant data has been wide-spreaded across various sites under many intentions, factualnote is a type of social software tool in which factual data are brought forward or narrow down to the web users."
        android:textColor="#ffffff"
        android:textSize="25sp"
        android:textStyle="normal|italic" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/url"
            android:layout_width="290dp"
            android:layout_height="33dip"
            android:layout_above="@+id/button_show"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center_horizontal"
            android:background="#ffffff"
            android:ems="17"
            android:hint="@string/edit_hint"
            android:radius="10dp"
            android:singleLine="true"
            android:text="http://www.zeptoh.com/lynked/sel.html"
            android:textColor="#000000"
            android:textSize="16sp" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/button_show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:background="@drawable/blue_button"
            android:text="@string/button_title"
            android:textColor="#ffffff" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/undo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_weight="9"
                android:background="@drawable/blue_button2"
                android:text="@string/undo"
                android:textColor="#ffffff" />

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_weight="9"
                android:background="@drawable/blue_button2"
                android:text="Mark"
                android:textColor="#ffffff" />

            <Button
                android:id="@+id/done"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_weight="10"
                android:background="@drawable/blue_button2"
                android:text="Generate"
                android:textColor="#ffffff" />

            <Button
                android:id="@+id/redo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_weight="9"
                android:background="@drawable/blue_button2"
                android:text="@string/redo"
                android:textColor="#ffffff" />
        </LinearLayout>
    </LinearLayout>

<RelativeLayout
        android:layout_width="fill_parent"
        android:id="@+id/rl2"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" >

    <EditText
        android:id="@+id/name"
        android:layout_width="250dp"
        android:layout_height="33dip"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="#ffffff"
        android:ems="17"
        android:layout_gravity="center_horizontal"
        android:hint="Enter Title"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="16sp" />    

    <EditText
        android:id="@+id/desc"
        android:layout_width="250dp"
        android:layout_height="33dip"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:background="#ffffff"
        android:ems="17"
        android:layout_gravity="center_horizontal"
        android:hint="Description about your note"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/privateText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/desc"
        android:layout_below="@+id/desc"
        android:layout_marginTop="10dp"
        android:text="Private Note:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ffffff"
        android:textSize="20sp"
        android:checked="true"
        android:buttonTint="@color/desing_color"
        android:textStyle="bold" />

    <RadioGroup
        android:id="@+id/radioSex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/privateText"
        android:layout_toRightOf="@+id/privateText"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="1dp"
            android:text="Yes"
            android:buttonTint="@color/desing_color"
            android:textColor="#ffffff"
            android:textSize="15sp"
            android:textStyle="bold" />

        <RadioButton
            android:id="@+id/no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/privateText"
            android:layout_marginLeft="14dp"
            android:layout_toRightOf="@+id/yes"
            android:text="No"
            android:textColor="#ffffff"
            android:textSize="15sp"
            android:checked="true"            
            android:buttonTint="@color/desing_color"
            android:textStyle="bold" />

    </RadioGroup>

    <Button
        android:id="@+id/generate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:background="@drawable/blue_button"
        android:layout_below="@+id/radioSex"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="70dp"
        android:textColor="#ffffff" 
        android:text="Generate Note" />

    <Button
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_below="@+id/radioSex"
        android:background="@drawable/blue_button"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="200dp"
        android:textColor="#ffffff" 
        android:text="Back" />

    </RelativeLayout>


    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

</RelativeLayout>

I put progress bar to center in horizontal and vertical. But that is placed on top of the screen only.

When I remove Linear layout rl2, progress bar appears center.

What I need to do to get progress bar in center even I have rl2.

Upvotes: 0

Views: 657

Answers (3)

AndreiBogdan
AndreiBogdan

Reputation: 11164

Did you try to remove android:gravity="fill" from the main container? (the first relative layout, the one that contains all the layout)

Upvotes: 0

X09
X09

Reputation: 3956

Try adding

android:layout_centerInParenta="true"

to the progressbar and tell me if it works.

Upvotes: 1

Ganesh Krishnamoorthy
Ganesh Krishnamoorthy

Reputation: 363

add the following line in your xml file,

<ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

if its not work, then first add progressbar and then add your views. Maybe it will work.

Upvotes: 0

Related Questions