Reputation: 1766
Currently I have a view within another view (its an ad) but because I am using MATCH_PARENT the width is the entire screen length when I only want it to be the ad size. Now WRAP_CONTENT fixes the problem but how do I centre the view on the bottom of the screen now? I was using the following code...
LinearLayout ll = new LinearLayout(this);
ll.setHorizontalGravity(Gravity.CENTER); //Place centre
ll.setVerticalGravity(Gravity.BOTTOM); //place bottom
mobfoxView = new MobFoxView(this, "xxxxxxxxxxxxxxxx", true, true);
mobfoxView.setBannerListener(this);
mobfoxView.setVisibility(View.GONE);
ll.addView(mobfoxView);
this.addContentView(ll, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
problem is that it wont centre anymore because of the WRAP_CONTENT. How do I get this to work so the layout is centred at the bottom of the screen?
Upvotes: 1
Views: 356
Reputation: 45942
Try these edits:
ll.setGravity(Gravity.CENTER | Gravity.BOTTOM);
mobfoxView = new MobFoxView(this, "xxxxxxxxxxxxxxxx", true, true);
mobfoxView.setBannerListener(this);
mobfoxView.setVisibility(View.GONE);
ll.addView(mobfoxView, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
this.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
In this way if ll is appended at the end of the tree it will fill everything and position on the bottom.
Upvotes: 1