Reputation: 443
I have a relativelayout
which contains a progressbar
and a Loading textview
..i need the progressbar
and text view to cone at the center of relative layout.But its coming more towards right not at the center.below is my code..
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="26dp"
android:layout_gravity="bottom"
android:background="@drawable/border">
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:id="@+id/progressBar"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/TextViewProgress"
android:text="Loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_toRightOf="@+id/progressBar"
/>
Upvotes: 2
Views: 3564
Reputation: 5803
add android:gravity="center"
to the RelativeLayout
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="26dp"
android:layout_gravity="bottom"
android:background="@drawable/border"
android:gravity="center">
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:id="@+id/progressBar"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/TextViewProgress"
android:text="Loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_toRightOf="@+id/progressBar" />
Upvotes: 5
Reputation: 10887
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="26dp"
android:layout_centerInParent="true"
android:background="@drawable/border">
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:id="@+id/progressBar"
android:layout_width="20dp"
android:layout_height="20dp"
/>
<TextView
android:id="@+id/TextViewProgress"
android:text="Loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_toRightOf="@+id/progressBar"
/>
Upvotes: 0
Reputation: 3192
This is Perfect i checked .
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/icon">
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:id="@+id/progressBar"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="5dp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/TextViewProgress"
android:text="Loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
Upvotes: 0
Reputation: 3254
Try adding a LinearLayout inside of it :
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="26dp"
android:layout_gravity="bottom"
android:background="@drawable/border">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
orientation="horizontal"
android:layout_centerInParent="true"
>
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:id="@+id/progressBar"
android:layout_width="20dp"
android:layout_height="20dp"
/>
<TextView
android:id="@+id/TextViewProgress"
android:text="Loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
/>
</LinearLayout>
</RelativeLayout>
It's just an example. I didn't test it.
Upvotes: 0