Android WebView在屏幕底部切断

时间:2014-05-08 13:31:17

标签: java android webview

我有一个使用网页浏览的应用程序。当我以编程方式将边距添加到webview所在的布局中时,它会切断webview的底部。我只注意到手机处于横向状态时,但是我尝试的一切都不起作用,如果我在webview中添加填充它什么都不做,如果我添加填充webview在里面的布局,它会添加填充但是仍然会关闭webview!

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>

边缘:

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:

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);
        }
    }
};

截图:

Correct Screenshot

Screenshot

当我在网页浏览中添加边距时,我无法理解为什么会这样做!它计算相对视图的高度,与我不添加边距时相同。显然,当我向左右添加边距时,网页视图的高度会变得更大。当我在布局中添加边距时,为什么没有找到正确的高度?感谢

0 个答案:

没有答案