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

标签 android android-relativelayout android-progressbar

我在相对布局中包含了一个进度条,但它在布局后面运行。有什么方法可以将它放在前面显示,以便在页面加载时显示它。

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

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

最佳答案

使用此代码:

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

希望这对你有帮助..

关于android - 如何将进度条置于布局顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45548212/

相关文章:

android - View 中的相等按钮宽度

Android RelativeLayout 有时会滚动

android - 尝试更改 Android ProgressBar 的圆角半径时出错

android - Activity 启动时软键盘不显示

android - 应用程序内的 float View

android - 如何在相对布局中正确居中一组按钮?

java - 当我尝试启动更改对象可见性的方法时,应用程序崩溃

android - 如何配置 Tensorflow 对象检测 Android 演示以使用 Inception v2

java - getStringExtra() 总是抛出 NullPointerException

java - 有api调用时如何在不重复代码的情况下膨胀progressBar布局