2015-02-05 56 views
0

我有我的Android應用程序的加載屏幕。中心ProgressBar和XML中的圖像android佈局

它的工作確定,如果我只用背景圖片或進度,但是當我嘗試在屏幕的中間居中這兩個元素,我得到的是:

layout_wrong

到目前爲止,我activityy_main.xml看起來像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/mainLayout" 
    tools:context="com.siconet.axa.MainActivity" > 

    <RelativeLayout 
     android:id="@+id/loadingPanel" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" > 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/axa_logo" /> 

     <ProgressBar 
      android:layout_width="250px" 
      android:layout_height="250px" 
      android:indeterminate="true" /> 

    </RelativeLayout> 

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

我想實現的是這樣的: enter image description here

回答

1

試試這個佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/mainLayout" 
    tools:context="com.siconet.axa.MainActivity" > 

    <RelativeLayout 
     android:id="@+id/loadingPanel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" > 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 

     <ProgressBar 
      android:layout_width="250px" 
      android:layout_height="250px" 
      android:layout_centerInParent="true" 
      android:indeterminate="true" /> 

    </RelativeLayout> 

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

希望這有助於你。

+0

謝謝,但它看起來完全一樣之前... – 2015-02-05 15:29:05

+0

如果您不介意,請檢查我的更新答案。 – 2015-02-05 15:41:53

+0

這正是我想要的!謝謝!!!! – 2015-02-05 16:07:57

1

請嘗試使用centerInParent。喜歡的東西...

<RelativeLayout 
    android:id="@+id/loadingPanel" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_centerInParent="true" > // right here 

但我認爲更好的辦法是隻使用一個LinearLayout。嘗試下面的佈局......

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/mainLayout" > 

<LinearLayout 
    android:id="@+id/loadingPanel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent ="true" 
    android:orientation="vertical"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/play" 
     android:layout_gravity="center_horizontal" /> 

    <ProgressBar 
     android:layout_width="250px" 
     android:layout_height="250px" 
     android:background="@drawable/pause" 
     android:indeterminate="true" /> 

</LinearLayout > 

<WebView 
    android:id="@+id/webView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:visibility="gone"/> 
</RelativeLayout> 

注意到不同的變化,但這種佈局使我下面......

enter image description here

我沒有看到你的ImageView第二圖像中,所以我第居中他們倆。如果你可以解釋應該在哪裏,那麼我可以調整這個佈局。

+0

看起來更糟... :(我恨佈局XDDDD – 2015-02-05 15:25:26

+0

你可以嘗試包裝在'LinearLayout'整個事情,使用'layout_gravity =「中心「老實說,這兩個圖像看起來和我一樣,如果不是在完成之前顯示webview,那麼你應該在第一個圖像中將可見性設置爲 – codeMagic 2015-02-05 15:28:20

+0

ProgressBar正處於圖像,第二個是居中.....關於'visibility'我以編程方式設置了需要的元素,但這不是問題。'webView'是一個phonegap應用程序,我有嵌套的佈局'loadingPanel'來顯示進度條在需要時在phoneGap應用的頂部... – 2015-02-05 15:32:56

1

嘗試添加到您的進度此行android:layout_centerInParent="true"

0

嘗試使用框架佈局,而不是在RelativeLayout的「loadingPanel」