I have an application that uses webviews. When I programmatically add margins to the layout the webview is in, it cuts off the bottom of the webview. I've only noticed it when the phone is in landscape, but everything I try doesn't work, if I add padding to the webview it does nothing, If I add padding the the layout the webview is inside, it adds the padding but the still cuts the webview off!
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/more_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent_black" >
<Button
android:id="@+id/test"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:onClick="onClickHandler"
android:text="@string/start_test" />
<WebView
android:id="@+id/top_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/test" />
<WebView
android:id="@+id/bottom_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/top_content" />
</RelativeLayout>
Side Margins:
public int getWebViewMargin() {
int screenWidth = getScreenWidth();
int sideMargin = 0;
int orientation = ((Activity) context).getResources().getConfiguration().orientation;
((Activity) context).getResources().getConfiguration();
int landscape = Configuration.ORIENTATION_LANDSCAPE;
if (GetScreenLayout() == ScreenSize.Xlarge){
sideMargin = screenWidth / 8;
} else if (GetScreenLayout() == ScreenSize.Large && orientation == landscape){
sideMargin = screenWidth / 9;
}
return sideMargin;
}
Height Margins:
public void setMarginHeight(final int marginHeight, int id) {
RelativeLayout buttonHolder = (RelativeLayout) ((Activity) context)
.findViewById(id);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
p.topMargin = marginHeight;
buttonHolder.setLayoutParams(p);
}
Runnable that calls the methods:
Runnable mAddMargin = new Runnable() {
@Override
public void run() {
try {
int marginHeight;
if (isPhone) {
marginHeight = activityHelper.getMarginHeight(R.id.more_info);
RelativeLayout buttonHolder = (RelativeLayout) findViewById(R.id.instructionsLayout);
mBottomOffset = buttonHolder.getBottom();
mScrollButton = (ScrollView) findViewById(R.id.scroll_view);
mYdelta = mScrollButton.getScrollY();
activityHelper.setMarginHeight(marginHeight, R.id.instructionsLayout);
} else if (!isPhone) {
int sideMargin = activityHelper.getWebViewMargin();
if(sideMargin != 0){
activityHelper.setWebViewMargin(sideMargin, R.id.top_content);
activityHelper.setWebViewMargin(sideMargin, R.id.bottom_content);
}
marginHeight = activityHelper.getMarginHeight(R.id.more_info);
activityHelper.setMarginHeight(marginHeight, R.id.more_info);
}
} catch (Exception e) {
Log.e("Scroll View", "Couldn't run mAddMargin:", e);
}
}
};
Screenshot:
I can't work out why it's doing it when I add margins to the webviews! it calculates the height of the relative view they're inside the same as when I don't add the side margin. obviously the webviews will get larger in height when I add margin to the left and right. Why is it not picking up the correct height when I add side margins to the layout? Thanks