简体   繁体   中英

android layout get framelayout always above tabwidget

Following layout is used to show views on tabcontent. However, when admob appears, framelayout goes down getting tabwidget on front. How could I set frameLayout always above tabwidget?? or the same, tabwidget below framelayout. Thank you

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              >


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

<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"
    android:id="@+id/mainLayout">


        <LinearLayout  
            android:id="@+id/mainLayout"
            android:orientation="vertical"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            >

                    <FrameLayout 
                        android:id="@android:id/tabcontent"
                        android:layout_width="fill_parent" 
                        android:layout_height="0dip"
                        android:layout_weight="1" 
                        android:scrollbars="none">
                    </FrameLayout>

            <TabWidget 
                android:id="@android:id/tabs"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:layout_weight="0"/>

        </LinearLayout>         
    </RelativeLayout>
</TabHost> 

</LinearLayout>

在此处输入图片说明

I see two issues in your layout that could be causing this. First, the layout_height of your TabHost should not be fill parent. If you want it to take up the remaining space in your layout (everything not taken by the ad), set the height to 0dip and the layout_weight to 1, like you did with your FrameLayout. Also, it looks like you have a LinearLayout nested in a RelativeLayout, one of which isn't necessary. For what you're trying, I would eliminate the RelativeLayout. You also may want to get rid of the layout_weight attribute on the TabWidget. Setting the Frame to 1 indicates that you want it to stretch to fill all the space remaining in the parent, and should give you the desired result. The widget's weight may be what's causing the overlap. Hope this helps.

It should be like so...

<TabHost>start

    <LinearLayout>start

        <com.google.ads.AdView
            start
            end />

        <FrameLayout>start

            <LinearLayout>start
            <LinearLayout>end

        </FrameLayout>end

        <TabWidget>start
        </TabWidget>end

    </LinearLayout>end

</TabHost>end

If you want to have the google adds change with the different tabs then the above way is best, but if you do not then just make it like this....

<LinearLayout>start

    <com.google.ads.AdView
        start
        end />

    <TabHost>start

        <LinearLayout>start

            <FrameLayout>start

                <LinearLayout>start
                <LinearLayout>end

            </FrameLayout>end

            <TabWidget>start
            </TabWidget>end

        </LinearLayout>end

    </TabHost>end

</LinearLayout>end

Also set the tab widget to android:layout_marginBottom="-4dp" just in case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM