Android 中间进度条在页面中间吗?

Android 中间进度条在页面中间吗?,android,Android,这是可行的,但它会将整个页面向下移动到中间,并将其替换为黑色背景。我的意思是它显示在页面的中间,而不是内容。内容被向下推 将相对布局更改为框架布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:la

这是可行的,但它会将整个页面向下移动到中间,并将其替换为黑色背景。我的意思是它显示在页面的中间,而不是内容。内容被向下推


将相对布局更改为框架布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true" />

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/progressBar1"
        />
</RelativeLayout>


这将完成你的工作。此外,此布局处理比RelativeLayout快得多,它将提高应用程序性能(用户看不到)

这可能对您有所帮助

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

 <ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />
</FrameLayout>


您可以根据自己的要求隐藏/显示进度条。相对而言,您可以将UI元素与其他元素进行比较。这就是为什么它会被推倒。您要么需要替换它,要么修改代码

在这种情况下,只需从WebView中删除android:layout_=“@+id/progressBar1”。这将重新定位中心的所有内容

现在,将WebView置于ProgressBar上方,将ProgressBar置于WebView上方进行查看

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"     />
    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true" />
</RelativeLayout>

在此代码中,您还可以使用FrameLayout代替RelativeLayout。希望这有帮助


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true" />

</RelativeLayout>

希望这能有所帮助。

我想你需要的是一个
ProgressDialog
。你可以使用下面的
android:layout_=“@+id/progressBar1”
删除这个
!更新了答案。progressbar必须写在webview下面。很棒的作品。如上所述,框架布局似乎更快。如何使用FrameLayout实现此功能?Simple只需将上面的代码微调器中的“”替换为“”,但该代码微调器未居中。不确定左上角的显示为什么有效。但是RelativeLayout并没有将它显示在左上方的微调器居中!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
</RelativeLayout>