gpt4 book ai didi

android - 如何在 LinearLayout 中设置 WebView

转载 作者:太空宇宙 更新时间:2023-11-03 11:44:37 24 4
gpt4 key购买 nike

我正在尝试在线性布局中设置 webview。我刚刚在线性布局中创建了一个 xml 线性布局文件、进度条和一个 webview..

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ProgressBar
android:id="@+id/progWeb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:max="100"
android:visibility="invisible" />

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

</LinearLayout>

java文件只显示进度条。此代码未显示 Webview

public class MainActivity extends Activity {

private WebView web;
private ProgressBar progBar;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.web);
progBar = (ProgressBar) findViewById(R.id.progWeb);

progBar.setVisibility(ProgressBar.INVISIBLE);
String url = "http://www.google.com.pk/";

web.getSettings().setJavaScriptEnabled(true);
web.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
System.out.println(progress);
progBar.setProgress(progress);

if (progress == 100) {
progBar.setVisibility(ProgressBar.INVISIBLE);
progBar.setProgress(0);
} else {
progBar.setVisibility(ProgressBar.VISIBLE);
}
}
});

web.loadUrl(url);

}
}

最佳答案

需要设置LinearLayout的方向为vertical,默认为horizo​​ntal

关于android - 如何在 LinearLayout 中设置 WebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com