First, my apologies for the title. I thought long and hard to choose a more descriptive title but couldn't really find one.
I have a screen with a header (variable length - using sliding action bar), a middle part (scrollview) and a bottom part for showing ads (fixed length). I am able to write the screen using RelativeLayout but what I would really like to do is this:
Imagine the scroll view's content as a short text or an image + a long text. For the first case, the scroll view content will be short and therefore I'd ideally show the ad at the bottom of the screen since I have enough space but if it's image + text, it will be larger than the screen height and as such, I would like to show the ad after the user has scrolled to the bottom.
The reason I want to do this is so that the ad doesn't necessarily take space if there's useful content on the screen (user experience).
Is there anyway to achieve this in android without writing my own custom layout? If so, which view would you recommend?
Many thanks in advance,
I don't think there is such a layout. You can do this programmatically. The ScrollView
always has a single child so you can get the content height this way:
int contentHeight = scrollView.getChildAt(0).getHeight();
You can get window height this way
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int windowHeight = size.y;
The height of the header and footer is fixed so you can do the maths decide where to put the footer.
int totalHeight = heaederHeight + contentHeight + footerHeight
if(totalHeight < windowHeight) {
// add the footer to the scrollview
} else {
// add the footer below the scrollview
}
The cons of this approach is that you have to do all the magic manually.
I hope this helped you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With