FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
FrameLayout f1 = new FrameLayout(this);
ac.addContentView(f1,lp );
我现在这样写,显示出来是在顶部,怎样才能让他贴着底部,并且左右居中?
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
FrameLayout f1 = new FrameLayout(this);
ac.addContentView(f1,lp );
我现在这样写,显示出来是在顶部,怎样才能让他贴着底部,并且左右居中?
大佬,你这ac是啥呀
private FrameLayout mBannerContainer = null;
/**
* 动态创建 FrameLayout 作为 Banner 广告的容器
*/
private void newBannerContainer(Activity activity) {
LinearLayout linearLayout = new LinearLayout(activity); // 创建帧布局对象layout
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
);
mBannerContainer = new FrameLayout(activity);
mBannerContainer.setVisibility(View.GONE);
linearLayout.addView(mBannerContainer, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
linearLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER);
activity.addContentView(linearLayout, layoutParams);// 显示布局管理器
}
填充广告后展示
mBannerContainer.setVisibility(View.VISIBLE);
隐藏
mBannerContainer.setVisibility(View.GONE);
应该是activity
大佬你显示成功没呀,我一点反应都没有
activity
一开始显示成功了,但第二天跑起来高度变得太大了,后来放弃了
Android中
mAdContainer = new FrameLayout(mActivity);
adLP = new FrameLayout.LayoutParams(adSlot.getWidth(), adSlot.getHeight());
mActivity.addContentView(mAdContainer, adLP);
adLP.leftMargin = adSlot.getLeft();
adLP.topMargin = adSlot.getTop();
mAdContainer.setLayoutParams(adLP);
mAdContainer.setVisibility(View.GONE);
Cocos中
let winSize = cc.winSize; // 屏幕大小
let worldARPos = this.node.parent.convertToWorldSpaceAR(this.node.position); // 转换成世界坐标
let worldPos = cc.v2(worldARPos.x - this.node.width * this.node.anchorX, cc.winSize.height - (worldARPos.y + this.node.height * (1 - this.node.anchorY))); // 转换成不带锚点以左上角为原点
// 换算成像素
let systemInfo = zs.getSystemInfoSync();
let widthPx = Math.ceil(this.node.width / winSize.width * systemInfo.windowWidth);
let heightPx = Math.ceil(this.node.height / winSize.height * systemInfo.windowHeight);
let marginLeftPx = Math.ceil(worldPos.x / winSize.width * systemInfo.windowWidth);
let marginTopPx = Math.ceil(worldPos.y / winSize.height * systemInfo.windowHeight);
return {
width: widthPx,
height: heightPx,
left: marginLeftPx,
top: marginTopPx
}
返回的参数,便是安卓中需要的四个参数,这样,你的node大小和位置就对应了安卓中控件容器的位置和大小