2013-01-02 27 views
2

我都含有progressbar和加載textview ..我一個relativelayout需要在相對layout.But其未來更向右不是在中心的中心progressbar和文本視圖,錐。下面是我的代碼..查看在該中心在RelativeLayout的

<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" 
         /> 
+0

也許問題是與你的RelativeLayout的容器。 RelativeLayout本身是否與其容器中的對齊? – peekler

+0

首先,將您的relativaLayout的高度更改爲 'match_parent'而不是'26dp',然後添加布局的完整xml代碼 – Houcine

+0

@Houcine:Thanks.but我需要控制相對佈局的高度。我有一個網格視圖,下面我添加這個相對佈局在屏幕的底部.. – user1340801

回答

5

添加android:gravity="center"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" /> 
+0

謝謝..它工作!!!!! – user1340801

+1

如果你有答案,請給出答案...... – Renjith

0

嘗試添加的LinearLayout它裏面:

<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> 

這只是一個例子。我沒有測試它。

0

這是完美的我檢查。

<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" 
         /> 
+0

如果你有答案,請給出答案...... –

0
  <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" 
        /> 
相關問題