Android 在相对视图的中心查看
我有一个Android 在相对视图的中心查看,android,view,android-relativelayout,Android,View,Android Relativelayout,我有一个relativelayout,其中包含一个progressbar和一个加载textview。我需要progressbar和文本视图在相对布局的中心呈锥形。但它更多的是向右,而不是在中心。下面是我的代码 <RelativeLayout android:layout_width="fill_parent" android:layout_height="26dp" android:layo
relativelayout
,其中包含一个progressbar
和一个加载textview
。我需要progressbar
和文本视图在相对布局的中心呈锥形。但它更多的是向右,而不是在中心。下面是我的代码
<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" />
尝试在其内部添加线性布局:
<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本身不是在它的容器中与右边对齐吗?首先,将您的相对长度更改为match_parent
而不是26dp
,然后添加您的相对长度的完整xml代码layout@Houcine:谢谢。但我需要控制相对布局的高度。例如,我有一个网格视图,在该视图下方,我将此相对布局添加到屏幕底部。@peekler:i-din-get你…你所说的相对论是什么意思right@user1340801:添加完整的xml布局代码,我们将帮助您解决此问题,这不是一个大问题相信我,只需编辑您的问题并添加完整的xml布局
<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"
/>