2016-12-07 57 views
0
<?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> 

这可行,但它将整个页面向下移动到中间并用黑色背景替换它。我的意思是它在页面中间显示不是内容。内容被推下。页面中间的中心进度条?

enter image description here

+0

我想你想要的是一个'ProgressDialog'。 –

+0

你可以使用[ProgressDialog](https://developer.android.com/reference/android/app/ProgressDialog.html) –

+1

删除这个'android:layout_below =“@ + id/progressBar1”'并按照@Reena的回答! – Piyush

回答

0

RelativeLayout将您的UI元素与其他元素进行比较。这就是为什么它被推倒了。您需要更换它,或者修改代码。从web视图 layout_below = “@ + ID/progressBar1”:

在这种情况下,只是删除机器人。这将所有内容重新定位在中心位置。

现在,将的WebView上述进度的WebView的顶部拿来和视图进度

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

您也可以在此代码中使用的FrameLayout代替RelativeLayout的。希望这可以帮助!

+0

感谢兄弟的作品。然而,RelativeLayout并不是将它显示在左上方的微调器居中! –

0

变化相对布局的FrameLayout。

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

这会帮你工作。另外这个布局处理比RelativeLayout的更快,这将提高应用程序的性能(对用户不可见)

+0

现在酒吧根本没有显示 –

+0

更新了答案。进度栏必须写在webview下面。 –

0

这可能有助于您

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

您可以隐藏/显示进度条按您的要求

+0

真棒作品很棒。如上所述,FrameLayout似乎更快。如何使这与FrameLayout工作? –

+0

简单只需要在上面的代码中将''替换为'' – Reena

+0

Spinner并不居中不确定为什么在左上角显示 –

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

希望这有助于..