2011-12-24 61 views
0

我試圖對齊選項卡布局頂部的廣告佈局,並沒有太大的運氣。它似乎卡在底部對齊。我已經配置了標籤佈局,使標籤是在屏幕的底部:對齊頂部的廣告佈局

<TabHost 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
> 

<RelativeLayout 
    android:id="@+id/adLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
> 
</RelativeLayout> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="0dp" 
    >   
     <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:padding="0dp" 
    /> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="23dp" 
     android:background="@drawable/tab_bg_selector" 
     android:layout_weight="0" 
    />  
</LinearLayout> 
</TabHost> 

更新:

我解決這個問題,我忘了我是設置對齊的代碼,如下所示:

final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 

一旦我將ALIGN_PARENT_BOTTOM更改爲ALIGN_PARENT_TOP,它就起作用了。

+0

大約一半,在的結束LinearLayout有一個'/>',它不應該在那裏。此外,我會嘗試將TabHost作爲一個FrameLayout,因爲它就是它的擴展。試着玩弄不同觀點的嚴重性。最後,您可以將TabHost放入ViewGroup中,並將adLayout放置在同一ViewGroup中的上方。 – 2011-12-24 05:15:13

+0

謝謝,我擺脫了額外的右括號 – 2011-12-24 15:20:30

回答

0

我不明白你的佈局結構,但我的理解是,你想在屏幕的頂部顯示廣告,併爲我修改代碼

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

     <RelativeLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent">   
      <RelativeLayout android:id="@+id/adLayout" 
       android:layout_width="fill_parent" android:layout_height="wrap_content" 
       android:layout_alignParentTop="true"> 
      </RelativeLayout> 
      <TabWidget android:id="@android:id/tabs" 
       android:layout_width="fill_parent" android:layout_height="wrap_content" 
       android:background="@drawable/tab_bg_selector" 
       android:layout_alignParentBottom="true" android:layout_weight="0" /> 
      <FrameLayout android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" android:layout_height="wrap_content" 
       android:layout_weight="1" android:padding="0dp" 
       android:layout_below="@id/adLayout" android:layout_above="@android:id/tabs"/> 
     </RelativeLayout> 
    </TabHost>