【发布时间】:2011-08-17 15:12:47
【问题描述】:
我正在尝试创建一个图像按钮来关闭来自 admob 的广告。 我在 xml 中创建了按钮,其可见性属性设置为“不可见”,然后在 java 上我在收到广告时将其设置为“可见”,但该按钮永远不会变得可见。 如果我将它设置为在 XML 上硬编码为“可见”,它会正常显示在屏幕上。
Admob 布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout_main">
<ImageButton
android:id="@+id/close_ad"
android:visibility="invisible"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-36dip"
android:layout_marginTop="12dip"
android:background="@drawable/btn_close_ad" />
</RelativeLayout>
添加广告:
private void addAd() {
rl = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.admob, null);
rl.setGravity(position);
activity.addContentView(rl, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
AdView admobView = new AdView(activity, AdSize.BANNER, Preferences.getAdmobKey());
admobView.loadAd(new AdRequest());
[ ... ]
admobView.setAdListener(new AdListener() {
@Override
public void onReceiveAd(Ad ad) {
Log.v("JeraAdmob", "onReceiveAd");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
createCloseButton();
}
}, AD_SHOW_CLOSE);
}
});
}
创建按钮以关闭广告:
private void createCloseButton() {
ImageButton button = (ImageButton) rl.findViewById(R.id.close_ad);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rl.removeAllViews();
handler.postDelayed(new Runnable() {
@Override
public void run() {
addAd();
rl.bringToFront();
}
}, AD_RELOAD);
}
});
button.setVisibility(View.VISIBLE);
button.bringToFront();
}
【问题讨论】:
-
你想把它放在广告的顶部吗? (重叠?)
-
你能改写你的问题吗 - 这句话是模棱两可的'......然后在java上我在收到广告时将它设置为“可见”,但按钮永远不会变得可见。如果我将它设置为“可见”,它会正常显示在屏幕上。这是否意味着当您将其设置为可见时它会出现或不出现 - 你已经说过了!
-
请显示按钮的xml代码的所有参数。
-
我正在尝试重叠,但左边距为负,它会出现在左侧,横幅之外。
-
如果我在 XML 上设置了硬编码的可见性“可见”,我试过这个来检查按钮是否在横幅下
标签: android eclipse android-layout admob imagebutton