Android图形高度在webview上

时间:2014-04-04 11:19:51

标签: java android android-layout webview

嗨我想在其内容呈现后计算height webview。我尝试了各种各样的工作。我这样做的原因是因为我需要在top_margin上设置Relative view,具体取决于webview的大小。

Activity:

Runnable mAddButtons = new Runnable() {
    @Override
    public void run() {
        try{

            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int ScreenHeight = metrics.heightPixels;

            RelativeLayout relLayout = (RelativeLayout) findViewById(R.id.more_info);
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);


            int height = relLayout.getHeight();

            int heightMargin = ScreenHeight - height;

            RelativeLayout buttonHolder = (RelativeLayout) findViewById(R.id.instructions);
            RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            lp.topMargin = heightMargin;
            mBottomOffset = buttonHolder.getBottom();
            mYdelta = mScrollButton.getScrollY();
            buttonHolder.setLayoutParams(lp);

            buttonHolder.requestLayout();

        }
        catch(Exception e){
            Log.e("Scroll View", "Couldn't run mAddButtons:", e);
        }
    }
};

MainLayout

     <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/right_hearing_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/photo_background_flip"
android:tag="layout" >

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fadingEdge="none" >
    <include layout="@layout/right_hearing_test_internal" />
</ScrollView>

,布局为:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/instructions"
    android:background="@color/transparent_black" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/more_info" >

        <WebView
            android:id="@+id/top_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/start_test"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/top_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="40dp"
            android:onClick="onClickHandler"
            android:text="@string/start_test" />

        <Button
            android:id="@+id/instructionsbutton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/start_test"
            android:background="@color/dark_gray"
            android:drawableLeft="@drawable/arrow_down_float"
            android:gravity="left"
            android:onClick="onMoreInstructions"
            android:paddingTop="6dp"
            android:text="MoreInstructions"
            android:textColor="@color/solid_white" />
    </RelativeLayout>

    <WebView
        android:id="@+id/bottom_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/more_info" />
</RelativeLayout>

0 个答案:

没有答案