如何将进度条置于布局顶部

8

我在相对布局中添加了一个进度条,但它在布局后面运行。有没有办法让它显示在前面,以便页面加载时显示。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@color/pageBackgroundColor"
    android:gravity="center"
    tools:context="co.sd.app.CheckoutActivity">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:visibility="visible" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/relativeLayout"
        android:layout_marginLeft="@dimen/page_marging_left"
        android:layout_marginRight="@dimen/page_marging_right">

        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/service_detail_cv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/shedule_apt_cv"
            android:layout_marginBottom="@dimen/dim_10sp"
            android:layout_marginTop="@dimen/dim_10sp"
            android:textColor="@color/darkGrey" />

    </RelativeLayout>

</RelativeLayout>

我不知道为什么显示成这样。

使用android:layout_centerInParent="true"与progressbar。 - USKMobility
1个回答

10

使用这段代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@color/pageBackgroundColor"
    android:gravity="center"
    tools:context="co.sd.app.CheckoutActivity">



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/relativeLayout"
        android:layout_marginLeft="@dimen/page_marging_left"
        android:layout_marginRight="@dimen/page_marging_right">

        <android.support.v7.widget.AppCompatTextView
            android:id="@+id/service_detail_cv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/shedule_apt_cv"
            android:layout_marginBottom="@dimen/dim_10sp"
            android:layout_marginTop="@dimen/dim_10sp"
            android:textColor="@color/darkGrey" />

    </RelativeLayout>

<ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:visibility="visible" />

</RelativeLayout>

希望这对你有帮助。


1
工作完成,谢谢 :) - Shamim Ahmad
也使用了约束布局。谢谢! - dcarl661

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接