typ*_*e34 2 android banner scrollview admob
嘿,到目前为止,我设法将Admob实施为正常的线性布局。现在,我添加了一个附加内容scrollview,然后adbanner消失了。我不知道该怎么做。
遵循来自.xml的代码,我在其中添加了scrollview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="match_parent">
<ScrollView android:id="@+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
[whole bunch of layout elements whoch shouldn´t affect the adbanner]
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
在我的线性布局中,adbanner仍然可以工作,整个adbanner的位置都在activitiy.java主文件中完成(在taiic.com的教程帮助下完成了此操作)
// Lookup R.layout.main
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
String pubID = "xxxxxxxxxxxxxxxxxx";
AdView adView = new AdView(this, AdSize.BANNER, pubID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
Run Code Online (Sandbox Code Playgroud)
在将admob标语实现为时,有人可以告诉我要更改什么或添加什么代码scrollview吗?
编辑:
我试图添加
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapprimaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
android:alignParentBottom="true"/>
Run Code Online (Sandbox Code Playgroud)
.xml中的最后两行之间
</LinearLayout>
[here]
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
但是然后我得到错误“错误:解析XML:未绑定前缀错误”
干杯
这是问题中的错字吗?myapprimaryTextColor="#FFFFFF"代替myapp:primaryTextColor="#FFFFFF"。这将给您xml解析错误。
使用RelativeLayout。工作代码在帖子末尾。首先,一些理论:)
ScrollView占据了整个屏幕,这就是为什么看不到admob视图的原因。定义了滚动视图后,所有屏幕都将显示在它的标签上,因此就可以使用它。admob视图实际上是在屏幕下方绘制的。可以在此示例中复制它:
非工作布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView android:id="@+id/scrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test1"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test2"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test3"
/>
</LinearLayout>
</ScrollView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test4"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如果改用RelativeLayout,则可以对其进行设置,使admob对齐屏幕的底部,并使其上方的滚动视图对齐,并占用剩余的可用空间。
工作布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test4"
android:id="@+id/test4"
android:layout_alignParentBottom="true"
/>
<ScrollView android:id="@+id/scrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above="@id/test4"
>
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test1"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test2"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test3"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4180 次 |
| 最近记录: |