0

我正在我的应用程序上实现 admob,它在父级处于相对布局时出现,但我不能使用alignparentbottom所以我将其更改为线性但当我将其更改为线性时它不显示..

有小费吗?帮助?

这是在xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/banner_holder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/offline_banner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@color/black"
            android:src="@drawable/offline_banner" />

        <com.google.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/unit_id"
            ads:loadAdOnCreate="true" />
    </RelativeLayout>
 <FrameLayout
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

我希望 admob 位于屏幕底部而不使用相对布局的alignparentbottom

4

2 回答 2

0

Not sure why you're avoiding alignParentBottom but the layout below worked for me.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

   <FrameLayout
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /> 
   <RelativeLayout
        android:id="@+id/banner_holder"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="bottom"
        android:weight="1" >

            <!-- Everything in here will hug the bottom -->

   </RelativeLayout>
</LinearLayout>
于 2013-11-11T03:51:14.417 回答
0
// try this 
1. download latest google-play-services,jar
2. add jar to project build path

**main.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/lnrMain">

</LinearLayout>

public class MyActivity extends FragmentActivity {

    LinearLayout lnrMain;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        lnrMain = (LinearLayout) findViewById(R.id.lnrMain);

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                AdView adView = new AdView(MyActivity.this);
                adView.setAdUnitId("0445b7141d9d4e1b");
                adView.setAdSize(AdSize.BANNER);
                AdRequest.Builder builder = new AdRequest.Builder();
                builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
                adView.loadAd(builder.build());
                lnrMain.addView(adView);
            }
        });

    }
}

**AndroidManifest.xml**
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.Demo"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk android:minSdkVersion="8"
        android:targetSdkVersion="17"/>
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher">
        <activity
            android:name="MyActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

        <meta-data
            android:name="ADMOB_ALLOW_LOCATION_FOR_ADS"
            android:value="true" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="4030500" />
    </application>
</manifest>
于 2013-11-11T04:40:30.010 回答