2011-12-24 6 views
0

Я пытаюсь выровнять макет объявления в верхней части макета вкладки, и мне не очень повезло. Кажется, что он застрял в нижней части. Я настроил Tab Layout так вкладки в нижней части экрана:Выравнивать рекламный макет наверху

<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> 

Update:

исправить это, я забыл, что я устанавливал выравнивание в коде, например:

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. –

+0

Спасибо, я избавился от этой дополнительной закрывающей скобки –

ответ

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> 
Смежные вопросы