在Webview中查看Android布局

zsohkypk  于 2023-05-05  发布在  Android
关注(0)|答案(4)|浏览(180)

我是新的Android应用程序.我只是想知道是否有一种方法来查看一个布局内的webview?例如。

WebView webview = (WebView)findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(true);
String url = "Layout location or R.Layout.test";
webview.loadUrl(url);

这就像使用Activity类来查看这样的布局setContentView(R.layout.test);
我正在尝试在web视图中查看布局。
任何想法都将受到高度赞赏。

brccelvz

brccelvz1#

无论你在教程中看到什么,我假设他们可能不会加载布局INTOWebView,而可能是along withWebView
换句话说,你实际上可以在HTML中使用类似于div的布局。你需要一个布局,在其中添加Webview,然后在Webview标签之外添加Button和其他控件,如lgw 150所示。

**这可能给予人的印象,按钮等是在webview内,但他们实际上不是!**你可以有这样的东西:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_height="fill_parent"
             android:layout_width="fill_parent"
             android:orientation="vertical">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button android:id="@+id/button1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"                
            android:layout_gravity="top"
            android:layout_weight="1"/>
        <Button android:id="@+id/button2"
            android:layout_width="0dip"
            android:layout_height="wrap_content"                
            android:layout_gravity="top"
            android:layout_weight="1" />
    </LinearLayout>
    <WebView 
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

更多信息请查看thisthis too

t98cgbkg

t98cgbkg2#

在webview中查看布局?我不是很明白,下面可能是一个例子给你

<ProgressBar
android:id="@+id/progWeb"
style="@style/progressbar"
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="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/progWeb"
android:layout_marginTop="28dp" />
nr9pn0ug

nr9pn0ug3#

需要说明的是,Web视图不能用于加载布局。
检查此链接
http://developer.android.com/reference/android/webkit/WebView.html

相关问题