开发者

how to shift the android layout when admob is available?

开发者 https://www.devze.com 2023-03-03 21:43 出处:网络
i\'m using this layout xml to show both my activity and the admob: first i thought it will shift the upper layout when the admob is available, but it is not...

i'm using this layout xml to show both my activity and the admob: first i thought it will shift the upper layout when the admob is available, but it is not... do you guys have any idea?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wonder"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
android:textColor="#000"
/>
<ListView
android:id="@+id/auto"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:headerDividersEnabled="false"
android:footerDividersEnabled="false"/>
<LinearLayout
xmlns:myapp="http://schemas.android.com/apk/res/com.anim.list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.admob.android.ads.AdView android:id="@+id/ad"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    myapp:backgroundColor="#000000" 
    myapp:primaryTextColor="#FFFFFF"
    myapp:secondaryTextColor="#CCCCCC" />
</LinearLayout>     
</LinearLayout>

Update: here's my RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.anim.list"
android:id="@+id/master"
android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/wonder"
 >
<TextView
android:id="@+id/inf"
android:layout_alignParentTop="true" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:text="@string/hello"
android:开发者_运维技巧textColor="#000"
/>   
<ListView
android:id="@+id/auto"
android:layout_above="@+id/ad"
android:layout_below="@+id/inf"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:headerDividersEnabled="false"
android:footerDividersEnabled="false"/>
<com.admob.android.ads.AdView 
    android:id="@+id/ad"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    myapp:backgroundColor="#000000" 
    myapp:primaryTextColor="#FFFFFF"
    myapp:secondaryTextColor="#CCCCCC"
    android:layout_alignParentBottom="true"
    />
</RelativeLayout>

how to shift the android layout when admob is available?

SOLVED

Sorry buddies, I use this layout to solve my problem

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:background="@drawable/wonder">
<LinearLayout android:layout_width="fill_parent"
              android:id="@+id/home_layout"
              android:orientation="vertical"
              android:layout_above="@+id/ad_layout"
              android:layout_height="wrap_content">
    <!-- Put all your application views here, such as buttons, textviews, edittexts and so on -->
    <TextView
        android:id="@+id/inf"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:textColor="#000"                
    />        
    <ListView
        android:id="@+id/auto"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:headerDividersEnabled="false"
        android:footerDividersEnabled="false"                
    />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
              android:id="@+id/ad_layout"
              android:layout_height="wrap_content"
              android:gravity="bottom"
              android:layout_alignParentBottom="true">
<com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res/com.anim.list"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="a14db7f475a6f8d"
/>
</LinearLayout>
</RelativeLayout>

Now, I got it works! thanks!


Remove your adview from xml instead change it to linearlayout

<LinearLayout
    android:layout_below="@+id/TextView01"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:id="@+id/layout_ad" android:layout_height="wrap_content"/>

and in your code

LinearLayout layout = (LinearLayout) findViewById(R.id.layout_ad);            

AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "your key");          
Display d = this.getWindowManager().getDefaultDisplay();    
RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(d.getWidth(), 52);        
layout.addView(adWhirlLayout, adWhirlLayoutParams);

This is how I implemented in my app


Use RelativeLayout and flag the upper view with layout:above="@+id/your_ad"

0

精彩评论

暂无评论...
验证码 换一张
取 消