0

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

3 回答 3

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>
于 2013-06-07T05:23:48.943 回答
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;
}

}
于 2013-06-06T12:17:40.533 回答
0

你需要另一个布局。FrameLayout 并不是在组件之间进行对齐的更好方法。如果您使用的是 FrameLayout,组件将被叠加。我建议您使用 LinearLayout 垂直或 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>
于 2013-06-06T12:35:54.263 回答