2014-12-27 52 views
0

我的代碼目前看起來像這樣進度不在中間

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 


<ProgressBar 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_gravity="center" 
    android:id="@+id/progressBar" /> 

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

我的進度僅在水平方向,而不是垂直居中。

我能得到它以兩種方式使用此代碼

<ProgressBar 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:layout_gravity="center" 
    android:id="@+id/progressBar" /> 

但中心則進度條(或相當紡)是大,因爲它可以得到,使其覆蓋整個屏幕。

任何解決方案,這樣我可以得到它在正常的高度和寬度爲中心。

+0

使用RelativeLayout – Rohit5k2

回答

1

如果您希望您的ProgressBar在屏幕的中心,並在WebView的頂部,你需要使用一個FrameLayoutRelativeLayout,像這樣:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <WebView 
     android:layout_width="match_parent" 
     android:layout_height="518dp" 
     android:id="@+id/webview" /> 
    <ProgressBar 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_gravity="center" 
     android:id="@+id/progressBar" /> 
</RelativeLayout> 

注意順序問題。 (WebView後)

1

儘量做到編程:

ProgressDialog dialog = new ProgressDialog(activity); 
dialog.setMessage("Loading..."); 
dialog.setCancelable(false); 
dialog.show(); 

我總是使它編程和運行良好(如預期)。