【问题标题】:AdMob Adview to a class which contains an inner classAdMob Adview 到包含内部类的类
【发布时间】:2013-07-30 00:17:00
【问题描述】:

我有一个内部类,它在我的活动中扩展 View 类。我将内容视图设置为内部类视图。我想在我的活动中添加一个 AdView。这是一个横幅..有人可以帮我实现这个吗?我是安卓新手..

类 MyActivity 扩展了 Activity {

  View myView;

     OnCreate()
      {
       myView= new ViewClass(this);
       setContentView(myView);
      }


   Class ViewClass extends View
     {
       //drawing inside a canvas and other drawing activities
     }

}

现在我想在屏幕上添加一个 AdView。我怎样才能做到这一点?

提前致谢

【问题讨论】:

    标签: android view admob adview


    【解决方案1】:

    在你的xml中添加你的视图类

    我们把它命名为myLayout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <package.MyActivity$ViewClass android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>
    
    <LinearLayout/>
    
    
    
    @Override
      onCreate()
      {
       setContentView(R.layout.myLayout);
       myView= (ViewClass)findViewById(R.id.viewClass);
    
      }
    

    更多关于creating a view class的信息。

    【讨论】:

    • 我已经通过添加一些示例代码编辑了这个问题。你能看一下吗?
    • 老兄,我怎样才能得到 ViewClass 类中绘制的东西?它包含一个画布和几个绘制到它的图像。如果我们将 contentView 设置为 myLayout,它只会显示指定的内容,对吗?提前致谢
    • myLayout.xml 包含对将在 setContentView 上绘制的 ViewClass 的引用。
    • 是的,我尝试这样做却遇到了错误。看来我们需要为此设置内部类静态。但它有几个对非静态外部类的引用。所以我发现这是第一个问题
    • 您可以测试但不要点击直播广告。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    相关资源
    最近更新 更多