简体   繁体   English

Android-在FrameLayout中将RelativeLayout居中对齐

[英]Android - align center the RelativeLayout in FrameLayout

adView is the AdMob's View and I am adding it to another frame view like this: adView是AdMob的视图,我将其添加到另一个框架视图中,如下所示:

adView = new AdView(this);

RelativeLayout relativeLayout = new RelativeLayout(this);
mFrameLayout.addView(relativeLayout);


RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
   AdView.LayoutParams.WRAP_CONTENT,
   AdView.LayoutParams.WRAP_CONTENT);
   //important I use this to make it appear on the bottom
adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);


relativeLayout.addView(adView, adViewParams);

It appear on the bottom of the frame layout, hence on the bottom of the screen (the frame layout is my screen). 它出现在框架布局的底部,因此出现在屏幕的底部(框架布局是我的屏幕)。 But is in not in the center, it is left aligned. 但是不在中心,它保持对齐。 How to align center the RelativeLayout in FrameLayout . 如何在FrameLayout对齐RelativeLayout中心。

EIDT: Here is the FrameLayout in case you need it: EIDT:如果需要,这是FrameLayout:

    // FrameLayout
    ViewGroup.LayoutParams framelayout_params =
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                   ViewGroup.LayoutParams.MATCH_PARENT);
    mFrameLayout = new FrameLayout(this);
    mFrameLayout.setLayoutParams(framelayout_params);

I have done this an it worked: 我做到了这一点,它的工作:

adViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);

Please confirm if it is correct. 请确认是否正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM