繁体   English   中英

以相对布局在中心查看

[英]View at the Center in a relativelayout

我有一个relativelayout其中包含一个progressbar和加载textview ..我所需要的progressbar和文本视图锥在相对layout.But其未来更向右不是在center.below是我的代码中心..

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

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

尝试在其中添加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>

这只是一个例子。 我没有测试。

我检查过,这很完美。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM