2012-07-28 29 views
2

我有一個滾動視圖內有3個視圖,我希望分佈在整個滾動視圖佈局中。我沒有得到它的正常工作,並希望有人看到這個問題。在滾動視圖內均勻分佈3個視圖

我想是滾動視圖中:

<scrollview> 
    <linear or relative view?> 
    (filler) 
    moneywheels 
    (filler) 
    timewheels 
    timeWheelsText 
    (filler) 
    </linear or relative view?> 
</scrollview> 

非常感謝您的幫助!

<ScrollView 
    android:id="@+id/ScrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:weightSum="3" > 

     <LinearLayout 
      android:id="@+id/fil1" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

     <LinearLayout 
      android:id="@+id/moneyWheels" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"> 

      <!-- content --> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/fill2" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

     <LinearLayout 
      android:id="@+id/timeWheels" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:background="@drawable/time" 
      android:padding="@dimen/padding" > 

      <!-- content --> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/timeWheelsText" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center" 
      android:layout_weight="0" 
      android:gravity="top|center" > 

      <!-- content --> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/fill3" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0" 
    android:gravity="bottom|center_horizontal" 
    android:orientation="vertical" > 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxxxxxxxxx" 
     ads:loadAdOnCreate="true" 
     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" /> 
</LinearLayout> 

+0

對於你的佈局,是兩個不同的文件,還是同一個? – MJD 2012-07-28 15:09:13

+0

佈局在一個文件中,是我在這裏發佈的內容。 – patrick 2012-07-28 15:17:57

回答

0

您的佈局XML文件無效。在處理XML時,您應該只有一個頂級標記。假設您希望廣告顯示滾動視圖下方,你想是這樣的:不是LinearLayouts

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0" 
    android:gravity="bottom|center_horizontal" 
    android:orientation="vertical" > 

    <ScrollView ...> 
     <!-- Other pieces under scrollview go here --> 
    </ScrollView> 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxxxxxxxxx" 
     ads:loadAdOnCreate="true" 
     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" /> 
</LinearLayout> 

此外,對於您的間隔,我建議只使用意見。視圖將是一個輕量級的類,不會使用盡可能多的資源。使用LinearLayouts進行間距可能會導致其他意外。

+0

謝謝!將LinearLayouts更改爲視圖並更改頂級標籤解決了我的問題。 – patrick 2012-07-28 17:19:32