如何在android布局中使用向上/向下滑动方法

时间:2017-09-25 10:05:24

标签: android android-layout android-animation android-library

enter image description here

嘿伙计我正在使用Two Relative layouts.one相对布局包括编辑框和微调器(Lime颜色布局)。其他相对布局仅包含web视图。我希望​​使用向上/向下滑动方法来相对布局(石灰色。)如果用户向上滑动石灰色的布局。其他布局将全屏显示。我不知道如何实现。我需要任何参考或文章来完成。谢谢提前          

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        android:background="#C6FF00">

        <LinearLayout
            android:id="@+id/linear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:background="#defec8">

            <EditText
                android:id="@+id/fromDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="From Date" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/linear1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="20dp"
            android:layout_toEndOf="@+id/linear"
            android:layout_toRightOf="@+id/linear"
            android:background="#defec8"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/todate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="To Date" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/linear2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="20dp"
            android:layout_toEndOf="@+id/linear1"
            android:layout_toRightOf="@+id/linear1"
            android:background="#defec8"
            android:orientation="horizontal">

            <Spinner
                android:id="@+id/timespinner"
                android:layout_width="80dp"
                android:layout_height="42dp" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/linear4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/linear"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp"
            android:background="#defec8"
            android:orientation="horizontal">

            <Spinner
                android:id="@+id/name"
                android:layout_width="match_parent"
                android:layout_height="40dp" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/linear5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/linear4"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:background="#defec8"
            android:orientation="horizontal">

            <Spinner
                android:id="@+id/nametype"
                android:layout_width="80dp"
                android:layout_height="40dp">

            </Spinner>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linear3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/linear4"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="20dp"
            android:layout_toEndOf="@id/linear5"
            android:layout_toRightOf="@id/linear5"
            android:background="#defec8"
            android:layout_marginBottom="10dp"
            android:orientation="horizontal">

            <Spinner
                android:id="@+id/digitspinner"
                android:layout_width="80dp"
                android:layout_height="40dp" />
        </LinearLayout>

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/linearweb"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/rL"
        android:layout_marginBottom="10dp">

        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </WebView>

    </LinearLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:3)

这对我来说很完美

  
      
  1. 我的自定义手势探测器类。复制并粘贴到适当的包中。
  2.   
  package com.cse.stackoverflow.gesture;

  import android.util.Log;
  import android.view.MotionEvent;
  import android.view.View;

  public abstract class CustomGestureDetector extends android.view.GestureDetector.SimpleOnGestureListener {

private static final String TAG = CustomGestureDetector.class.getSimpleName();

private View view;

private boolean selectionStart;

public CustomGestureDetector(View view) {
    this.view = view;
}

//FOR GESTURE
@Override
public boolean onFling(MotionEvent motionEventOne, MotionEvent motionEventTwo, float velocityX, float velocityY) {
    if (motionEventOne == null || motionEventTwo == null) {
        return false;
    } else if (motionEventOne.getPointerCount() > 1 || motionEventTwo.getPointerCount() > 1) {
        return false;
    } else {
        if (isSelectionStart()) {

            Log.d(TAG, "ME 1 : X - " + motionEventOne.getX());
            Log.d(TAG, "ME 1 : Y - " + motionEventOne.getY());
            Log.d(TAG, "ME 2 : X - " + motionEventTwo.getX());
            Log.d(TAG, "ME 2 : Y - " + motionEventTwo.getY());
            Log.d(TAG, "Velocity Of X - " + velocityX);
            Log.d(TAG, "Velocity Of Y - " + velocityY);

        } else {

            try {
                ///////////////////////////////////////////////////////////////////////////////

                Log.d(TAG, "ME 1 : X - " + motionEventOne.getX());
                Log.d(TAG, "ME 1 : Y - " + motionEventOne.getY());
                Log.d(TAG, "ME 2 : X - " + motionEventTwo.getX());
                Log.d(TAG, "ME 2 : Y - " + motionEventTwo.getY());
                Log.d(TAG, "Velocity Of X - " + velocityX);
                Log.d(TAG, "Velocity Of Y - " + velocityY);

                float mRightToLeftCover = motionEventOne.getX() - motionEventTwo.getX();

                float mTopToBottomCover = motionEventTwo.getY() - motionEventOne.getY();

                float mVelocityX = velocityX;

                float mVelocityY = velocityY;

                Log.i(TAG, "mRightToLeftCover : " + mRightToLeftCover);

                Log.i(TAG, "mTopToBottomCover : " + mTopToBottomCover);

                Log.i(TAG, "mVelocityX : " + mVelocityX);

                Log.i(TAG, "mVelocityY : " + mVelocityY);

                if (mRightToLeftCover >= 0) {
                    if (mTopToBottomCover >= 0) {
                        if (mTopToBottomCover < 100) {
                            if (mRightToLeftCover > 100) {
                                Log.d(TAG, "1. R =>> L");
                                onRightToLeftSwap();
                            }
                        } else {
                            if (mRightToLeftCover < 100) {
                                Log.d(TAG, "9. T ==>> B");
                                onTopToBottomSwap();
                            } else {
                                Log.d(TAG, "2. T ==>> B, R =>> L");
                            }
                        }
                    } else {
                        if (mTopToBottomCover > -100) {
                            if (mRightToLeftCover > 100) {
                                Log.d(TAG, "3. R =>> L");
                                onRightToLeftSwap();
                            }
                        } else {
                            if (mRightToLeftCover < 100) {
                                Log.d(TAG, "10. B ==>> T");
                                onBottomToTopSwap();
                            } else {
                                Log.d(TAG, "4. B ==>> T, R =>> L");
                            }
                        }
                    }
                } else if (mRightToLeftCover < 0) {
                    if (mTopToBottomCover >= 0) {
                        if (mTopToBottomCover < 100) {
                            if (mRightToLeftCover > -100) {
                                Log.d(TAG, "5. L =>> R");
                                onLeftToRightSwap();
                            }
                        } else {
                            if (mRightToLeftCover > -100) {
                                Log.d(TAG, "11. T ==>> B");
                                onTopToBottomSwap();
                            } else {
                                Log.d(TAG, "6. T ==>> B, L =>> R");
                            }
                        }
                    } else {
                        if (mTopToBottomCover > -100) {
                            if (mRightToLeftCover < -100) {
                                Log.d(TAG, "7. L =>> R");
                                onLeftToRightSwap();
                            }
                        } else {
                            if (mRightToLeftCover < -100) {
                                Log.d(TAG, "12. B ==>> T");
                                onBottomToTopSwap();
                            } else {
                                Log.d(TAG, "8. B ==>> T, L =>> R");
                            }
                        }
                    }
                }

                return true;

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        //////////////////////////////////////////////////////////////////////////////


        return false;
    }
}

//EXPERIMENTAL PURPOSE
public abstract void onLeftToRightSwap();

public abstract void onRightToLeftSwap();

public abstract void onTopToBottomSwap();

public abstract void onBottomToTopSwap();

public abstract void onLeftToRightTopToBottomDiagonalSwap();

public abstract void onLeftToRightBottomToTopDiagonalSwap();

public abstract void onRightToLeftTopToBottomDiagonalSwap();

public abstract void onRightToLeftBottomToTopDiagonalSwap();

//SINGLE AND DOUBLE TABS
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    Log.d(TAG, "On Single Tap");
    Log.d(TAG, "Selection Start : " + selectionStart);
    Log.d(TAG, "ME 1 : X - " + e.getX());
    Log.d(TAG, "ME 1 : Y - " + e.getY());
    onSingleTap();
    return super.onSingleTapConfirmed(e);
}

@Override
public boolean onDoubleTap(MotionEvent e) {
    Log.d(TAG, "On Double Tap");
    onDoubleTap();
    return super.onDoubleTap(e);
}

public abstract void onSingleTap();

public abstract void onDoubleTap();

public boolean isSelectionStart() {
    return selectionStart;
}

public void setSelectionStart(boolean selectionStart) {
    this.selectionStart = selectionStart;
}

@Override
public void onLongPress(MotionEvent e) {
    onLongPressPerformed(e);
    super.onLongPress(e);
}

public abstract void onLongPressPerformed(MotionEvent e);
  }
  
      
  1. activity_main.xml只是很小的修改,即我将id“webView”设置为你的webView。 (将此xml代码复制并粘贴到xml文件中)。
  2.   
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout
    android:id="@+id/rL"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#C6FF00">

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:background="#defec8">

        <EditText
            android:id="@+id/fromDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="From Date" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:layout_toEndOf="@+id/linear"
        android:layout_toRightOf="@+id/linear"
        android:background="#defec8"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/todate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="To Date" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:layout_toEndOf="@+id/linear1"
        android:layout_toRightOf="@+id/linear1"
        android:background="#defec8"
        android:orientation="horizontal">

        <Spinner
            android:id="@+id/timespinner"
            android:layout_width="80dp"
            android:layout_height="42dp" />
    </LinearLayout>


    <LinearLayout
        android:id="@+id/linear4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linear"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="20dp"
        android:background="#defec8"
        android:orientation="horizontal">

        <Spinner
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="40dp" />
    </LinearLayout>


    <LinearLayout
        android:id="@+id/linear5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/linear4"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:background="#defec8"
        android:orientation="horizontal">

        <Spinner
            android:id="@+id/nametype"
            android:layout_width="80dp"
            android:layout_height="40dp">

        </Spinner>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linear4"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="20dp"
        android:layout_toEndOf="@id/linear5"
        android:layout_toRightOf="@id/linear5"
        android:background="#defec8"
        android:layout_marginBottom="10dp"
        android:orientation="horizontal">

        <Spinner
            android:id="@+id/digitspinner"
            android:layout_width="80dp"
            android:layout_height="40dp" />
    </LinearLayout>

</RelativeLayout>

<LinearLayout
    android:id="@+id/linearweb"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/rL"
    android:layout_alignParentBottom="true">

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

    </WebView>

</LinearLayout>

</RelativeLayout>
  
      
  1. MainActivity代码(复制并粘贴所有方法并在onCreate()中调用initialiseView()方法)
  2.   
public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initialiseView();

}

RelativeLayout upperLayout;
LinearLayout lowerLayout;
WebView mWebView;

private void initialiseView() {

    upperLayout = (RelativeLayout) findViewById(R.id.rL);

    lowerLayout = (LinearLayout) findViewById(R.id.linearweb);

    mWebView = (WebView) findViewById(R.id.webView);

    CustomGestureDetector mCustomGestureDetectorForUpperLayout = new CustomGestureDetector(upperLayout) {
        @Override
        public void onLeftToRightSwap() {

        }

        @Override
        public void onRightToLeftSwap() {

        }

        @Override
        public void onTopToBottomSwap() {
            //Toast.makeText(MainActivity.this, "onTopToBottomSwap", Toast.LENGTH_SHORT).show();
            showUpperLayout();
        }

        @Override
        public void onBottomToTopSwap() {
            //Toast.makeText(MainActivity.this, "onBottomToTopSwap", Toast.LENGTH_SHORT).show();
            hideUpperLayout();

        }

        @Override
        public void onLeftToRightTopToBottomDiagonalSwap() {

        }

        @Override
        public void onLeftToRightBottomToTopDiagonalSwap() {

        }

        @Override
        public void onRightToLeftTopToBottomDiagonalSwap() {

        }

        @Override
        public void onRightToLeftBottomToTopDiagonalSwap() {

        }

        @Override
        public void onSingleTap() {

        }

        @Override
        public void onDoubleTap() {

        }

        @Override
        public void onLongPressPerformed(MotionEvent e) {

        }
    };

    final GestureDetector mGestureDetectorUpperLayout = new GestureDetector(this, mCustomGestureDetectorForUpperLayout);

    CustomGestureDetector mCustomGestureDetectorForLowerLayout = new CustomGestureDetector(lowerLayout) {
        @Override
        public void onLeftToRightSwap() {

        }

        @Override
        public void onRightToLeftSwap() {

        }

        @Override
        public void onTopToBottomSwap() {
            showUpperLayout();
        }

        @Override
        public void onBottomToTopSwap() {

        }

        @Override
        public void onLeftToRightTopToBottomDiagonalSwap() {

        }

        @Override
        public void onLeftToRightBottomToTopDiagonalSwap() {

        }

        @Override
        public void onRightToLeftTopToBottomDiagonalSwap() {

        }

        @Override
        public void onRightToLeftBottomToTopDiagonalSwap() {

        }

        @Override
        public void onSingleTap() {

        }

        @Override
        public void onDoubleTap() {

        }

        @Override
        public void onLongPressPerformed(MotionEvent e) {

        }
    };

    final GestureDetector mGestureDetectorLowerLayout = new GestureDetector(this, mCustomGestureDetectorForLowerLayout);

    upperLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            mGestureDetectorUpperLayout.onTouchEvent(motionEvent);

            return true;
        }
    });

    lowerLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            mGestureDetectorLowerLayout.onTouchEvent(motionEvent);

            return true;
        }
    });

    mWebView.loadUrl("https://www.google.co.in/");

    CustomGestureDetector mCustomGestureDetectorForWebView = new CustomGestureDetector(mWebView) {
        @Override
        public void onLeftToRightSwap() {

        }

        @Override
        public void onRightToLeftSwap() {

        }

        @Override
        public void onTopToBottomSwap() {
            showUpperLayout();
        }

        @Override
        public void onBottomToTopSwap() {
            hideUpperLayout();
        }

        @Override
        public void onLeftToRightTopToBottomDiagonalSwap() {

        }

        @Override
        public void onLeftToRightBottomToTopDiagonalSwap() {

        }

        @Override
        public void onRightToLeftTopToBottomDiagonalSwap() {

        }

        @Override
        public void onRightToLeftBottomToTopDiagonalSwap() {

        }

        @Override
        public void onSingleTap() {

        }

        @Override
        public void onDoubleTap() {

        }

        @Override
        public void onLongPressPerformed(MotionEvent e) {

        }
    };

    final GestureDetector mGestureDetectorForWebView = new GestureDetector(this, mCustomGestureDetectorForWebView);

    mWebView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            mGestureDetectorForWebView.onTouchEvent(motionEvent);

            return true;
        }
    });
}

public void hideUpperLayout() {
    upperLayout.setVisibility(View.GONE);

}

public void showUpperLayout() {
    upperLayout.setVisibility(View.VISIBLE);
}

public void toggleUpperLayout() {
    if (upperLayout.getVisibility() == View.VISIBLE) {
        hideUpperLayout();
    } else {
        showUpperLayout();
    }
}
}
  
      
  1. 这是可选的(在您的网页浏览中查看Google主页)。   //在AndroidMenifest.xml中添加互联网权限
  2.   
<uses-permission android:name="android.permission.INTERNET" />

按评论更新为平滑滚动

  

要实现平滑滚动,您需要在父布局中使用AppBarLayout(父布局可以是任何易于使用的协调器布局)。

     
      
  1. 首先在style.xml中创建如下所示的主题条目,或者只复制并粘贴它。
  2.   
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
  
      
  1. 对于需要创建colors.xml的颜色(如果您创建的应用程序具有默认条目)
  2.   
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
  
      
  1. 现在您的activity_main.xml如下所示。
  2.   
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.cse.scrolltoolbar.ScrollingActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:id="@+id/rL"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#C6FF00"
            android:paddingTop="100dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <LinearLayout
                android:id="@+id/linear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:background="#defec8">

                <EditText
                    android:id="@+id/fromDate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:hint="From Date" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:layout_marginTop="20dp"
                android:layout_toEndOf="@+id/linear"
                android:layout_toRightOf="@+id/linear"
                android:background="#defec8"
                android:orientation="horizontal">

                <EditText
                    android:id="@+id/todate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:hint="To Date" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:layout_marginTop="20dp"
                android:layout_toEndOf="@+id/linear1"
                android:layout_toRightOf="@+id/linear1"
                android:background="#defec8"
                android:orientation="horizontal">

                <Spinner
                    android:id="@+id/timespinner"
                    android:layout_width="80dp"
                    android:layout_height="42dp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/linear"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="20dp"
                android:background="#defec8"
                android:orientation="horizontal">

                <Spinner
                    android:id="@+id/name"
                    android:layout_width="match_parent"
                    android:layout_height="40dp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/linear4"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:background="#defec8"
                android:orientation="horizontal">

                <Spinner
                    android:id="@+id/nametype"
                    android:layout_width="80dp"
                    android:layout_height="40dp">

                </Spinner>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/linear4"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="40dp"
                android:layout_marginTop="20dp"
                android:layout_toEndOf="@id/linear5"
                android:layout_toRightOf="@id/linear5"
                android:background="#defec8"
                android:orientation="horizontal">

                <Spinner
                    android:id="@+id/digitspinner"
                    android:layout_width="80dp"
                    android:layout_height="40dp" />
            </LinearLayout>

        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<!--<include layout="@layout/content_scrolling" />-->

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

</WebView>

</android.support.design.widget.CoordinatorLayout>
  
      
  1. 在清单文件中添加互联网权限,并添加以下方法将Google主页加载到您的网络视图,并在setContentView之后从onCreate调用此方法。
  2.   
    private void initialiseView() {

    WebView mWebView = (WebView) findViewById(R.id.webView);

    mWebView.loadUrl("https://www.google.co.in/");


    }