2016-12-07 58 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> 

希望這有助於..