Webview将在主要布局下方显示其内容

时间:2012-06-19 07:47:10

标签: android android-layout android-intent

我已经为我的Android应用程序创建了一个webview,我正在努力使应用程序更简单,以便了解事情。我创建了一个webview来显示其中的不同页面。我只是创建了一个按钮,将网址加载到webview中,工作得非常好,但是webview正在加载按钮下方的网址。它不会覆盖主要布局或不在新页面中打开网址。我在webview中看到了网页,上面是按钮。怎么能摆脱这个按钮。提前致谢。这是我的java和xml代码

活性

public class TestinglinkActivity extends Activity {
     final Activity activity = this;
     WebView webview;

    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;


        }
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient(new MyWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {
            activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if(progress == 100)
                activity.setTitle(R.string.app_name);
        }
    });


    Button btn_login = (Button) findViewById(R.id.btn_click_login);
    btn_login.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
             webview.loadUrl("http://www.google.com.pk");
             webview.goBack();
             webview.goForward();

          }
         }
     );


           }




}

XML

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:isScrollContainer="true" 
        android:scrollbarAlwaysDrawVerticalTrack="true" 
        android:scrollbarStyle="outsideInset" 
        android:scrollbars="vertical"  
        android:scrollbarSize="10dp"
        >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <Button 
            android:id="@+id/btn_click_login"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_weight="2"
            android:text="GO"/>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <TextView
        android:id="@+id/date"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:layout_marginRight="5dp"
        android:layout_alignParentLeft="true"
        android:gravity="center_vertical"
        android:lines="4"

        />
     <ImageView android:id="@+id/imageBtn"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:padding="5dp"
        android:contentDescription="@string/hello"
        android:layout_alignParentLeft="true"

         />

</RelativeLayout>

      <TextView
        android:id="@+id/date"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:gravity="center_vertical"
        android:lines="4"

        />

    <WebView 
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>


</LinearLayout>

 </ScrollView>

1 个答案:

答案 0 :(得分:0)

听起来我想要在按下按钮时启动一个新的Activity。 WebView出现在另一个布局下面的原因是因为这正是XML所描述的内容。如果您希望WebView全屏显示,则需要将WebView移动到单独的Activity,该Activity在单击按钮时启动。

您可能希望传递用于启动新活动的Extra of Intent中的URL。