在framelayout中的进度条下方显示webview

时间:2013-06-06 12:13:51

标签: android android-framelayout

我想在进度条下面显示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>

3 个答案:

答案 0 :(得分:1)

我用过这个并解决了我的问题...

<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>

答案 1 :(得分:0)

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

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;
}

}

答案 2 :(得分:0)

您需要另一个布局。 FrameLayout不是在组件之间进行对齐的更好方法。如果您使用的是FrameLayout,则会叠加组件。我建议你使用LinearLayout vertical或RelativeLayout。

试试这个:

<?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>