按钮不显示在 webview 旁边

Button does not show next to a webview


我的应用程序包含一个制表符 activity。在一个选项卡中,我显示了一个 webview,我想在其下显示几个按钮。
我发布的代码现在可以使用了!
感谢帮助

package com.whateveryoulike.whateveryoulike;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class Activity_tab_reader extends Activity {

private WebView webView;

// entnimmt die url aus dem public static string und legt sie in der localen string    mynewurl ab.
String MyNewUrl =  Activity_Haupt.MyDocumentURL;
//String data = "<html><head></head><body>this should be my long long text...</body></html>";


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

    MyNewUrl =  Activity_Haupt.MyDocumentURL;
    webView = (WebView) findViewById(R.id.webview);
    webView.loadUrl(MyNewUrl);

    //Settings webview
    webView.getSettings().setJavaScriptEnabled(true); // enable javascript
    webView.getSettings().setSaveFormData(true);

    final Activity activity = this;

    webView.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
        }
    });     
}

    @Override
    protected void onResume() {
        super.onResume();
        if(!MyNewUrl.equals(Activity_Haupt.MyDocumentURL)){

            MyNewUrl =  Activity_Haupt.MyDocumentURL;   
            webView.loadUrl(MyNewUrl);

        }
    }
}

这是 tabxml 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fh_blau"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3" >

        <Button
            android:id="@+id/btnRefresh"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/btnNext"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/btnCloseSearch"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />
    </LinearLayout>

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

</RelativeLayout>

感谢帮助

根据你编辑的问题,下面的代码应该可以工作,当你使用 RelativeLayout 时,你必须让小部件知道它们需要在哪里,使用 layout_above/layout_below 和 RelativeLayout 的属性 编辑:我添加了 setContentView(R.id.tab) 更改 "tab" 和您的 xml 文件名。 并在复制粘贴之前尝试学习代码

你的Activity,

 public class Activity_tab_reader extends Activity {

    private WebView webView;

    // entnimmt die url aus dem public static string und legt sie in der localen string mynewurl ab.
    String MyNewUrl =  Activity_Haupt.MyDocumentURL;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);
        webView  = (WebView) findViewById(R.id.webview);
//    do the same as above here to initialize buttons and handle their clicks.
    MyNewUrl =  Activity_Haupt.MyDocumentURL;   
        webView.loadUrl(MyNewUrl);
        //webView.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "utf-8", null);
        webView.getSettings().setJavaScriptEnabled(true); // enable javascript
        webView.getSettings().setSaveFormData(true);
        //webView.getSettings().setBuiltInZoomControls(true);
        //webView.getSettings().setSupportMultipleWindows(true);
        final Activity activity = this;

        webView.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
            }
        });
    //  webView .loadUrl("http://www.google.com");

    }

    @Override
    protected void onResume() {
        super.onResume();
        if(!MyNewUrl.equals(Activity_Haupt.MyDocumentURL)){

            MyNewUrl =  Activity_Haupt.MyDocumentURL;   
            webView.loadUrl(MyNewUrl);
        }
    }

和选项卡 xml文件,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fh_blau"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3" >

        <Button
            android:id="@+id/btnRefresh"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/btnNext"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/btnCloseSearch"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />
    </LinearLayout>

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

</RelativeLayout>