Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在framelayout中的progressbar下方显示webview_Android_Android Framelayout - Fatal编程技术网

Android 在framelayout中的progressbar下方显示webview

Android 在framelayout中的progressbar下方显示webview,android,android-framelayout,Android,Android Framelayout,我想在progressbar下面显示webview。怎么做? 我的代码如下: <FrameLayout android:id="@+id/flWeb" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" > <ProgressBar android

我想在progressbar下面显示webview。怎么做?
我的代码如下:

<FrameLayout
        android:id="@+id/flWeb"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ProgressBar
            android:id="@+id/pbWebsite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|top" />

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

</FrameLayout>

这是我用来显示进度的代码:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
WebView mWvUrl;

@Override
protected void onCreate(Bundle savedInstanceState) {
final Activity activity=this;
super.onCreate(savedInstanceState);

getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
activity.setProgressBarIndeterminateVisibility(false);
 mWvUrl = (WebView) findViewById(R.id.wv_url);

 mWvUrl.getSettings().setJavaScriptEnabled(true);
 Button btnLoad = (Button) findViewById(R.id.btn_load);
 btnLoad.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
         EditText etUrl = (EditText) findViewById(R.id.et_url);
          mWvUrl.loadUrl(etUrl.getText().toString());
          activity.setProgressBarIndeterminateVisibility(true);
    }
});

 mWvUrl.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            /** This prevents the loading of pages in system browser */
            return false;
        }

        /** Callback method, executed when the page is completely loaded */
        @Override
        public void onPageFinished(WebView view, String url) {
             super.onPageFinished(view, url);

             Toast.makeText(getBaseContext(),
                            "Page loaded Completely",
                            Toast.LENGTH_SHORT).show();

            /** Hiding Indeterminate Progress Bar in the title bar*/
            activity.setProgressBarIndeterminateVisibility(false);

        }

    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

}

你需要另一个布局。FrameLayout不是在组件之间进行对齐的更好方法。如果使用的是框架布局,则将叠加组件。我建议您使用线性垂直布局或相对布局

试试这个:

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

 <ProgressBar
            android:id="@+id/pbWebsite"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center|top" />

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

我用这个解决了我的问题

<FrameLayout
        android:id="@+id/flWebpre"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

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

        <ProgressBar
            android:id="@+id/pbWebsite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:layout_gravity="center_horizontal" />
    </FrameLayout>


我想使用clickevent,因此无法使用relativeLayout。如果您解决了它,请在解决方案中发布答案,以便其他人可以从中学习。每个人都讨厌回答“没关系,我自己解决了”的问题。