【问题标题】:How to display Image over a WebView?如何在 WebView 上显示图像?
【发布时间】:2017-04-28 04:57:16
【问题描述】:

我正在开发一个应用程序,我想要在 WebView 上显示图像(图像在 WebView 之上)。我搜索了谷歌并尝试了很多东西。但它不起作用。

在 XML 的设计选项卡中,我可以在 WebView 上看到图像。但是当我在手机中加载应用程序时,图像不会出现,但网页会加载。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
xmlns:fab="http://schemas.android.com/tools">
<ImageView
android:id="@+id/fabButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginRight="24dp"
app:srcCompat="@drawable/imag1"
android:elevation="2dp"
android:layout_marginEnd="41dp"

android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
 />


<WebView
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:id="@+id/webView"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

</RelativeLayout>

提前感谢您的帮助。 我不知道它是否会影响代码,但我正在尝试在片段中执行此操作

【问题讨论】:

  • 在您的 web 视图之后添加您的图像视图。 ViewGroup 主要以孩子先到先得为基础,因此在您的代码中 webviews 隐藏了 ImageView

标签: android webview imageview


【解决方案1】:

我希望它会对某人有所帮助。这是我使用的代码:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:background="#FFFFFF"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="3dp"
        tools:context=".CategoryActivity">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/inset_web_view"
            android:background="#FFFFFF"
            android:orientation="vertical">

            <TextView
                android:id="@+id/authTextView"
                android:layout_marginTop="60dp"
                android:layout_width="wrap_content"
                android:textStyle="bold"
                android:layout_height="wrap_content"
                android:text="Programs"
                android:textColor="@color/colorPrimary"
                android:textSize="20dp"/>

            <ScrollView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:scrollbars="horizontal|vertical"
                android:scrollbarStyle="outsideInset"
                android:fillViewport="true">


                <WebView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="@string/programs"
                    android:textColor="#000"
                    android:textSize="18sp"
                    android:textStyle="normal" />

            </ScrollView>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <Button
                android:id="@+id/viewButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_alignParentBottom="true"
                android:background="@drawable/roundedbutton"
                android:onClick="clickEvent"
                android:padding="5dp"
                android:text="@string/apply_now"
                android:textColor="#fff"
                android:textSize="15sp"
                android:textStyle="bold" />
        </LinearLayout>
</LinearLayout>

【讨论】:

    【解决方案2】:
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <?xml version="1.0" encoding="utf-8"?>
    
    
    
        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/webView"
             />
        <ImageView
            android:id="@+id/fabButton"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginBottom="24dp"
            android:layout_marginRight="24dp"
            android:src="@drawable/circle"
            android:elevation="2dp"
            android:layout_marginEnd="21dp"
            android:layout_gravity="bottom|right"
    
            />
    </FrameLayout>
    

    【讨论】:

    • 我试过你的代码,但仍然没有出现。如果我没有要加载的网站,图像是可见的,但是当网站加载时它不会出现
    猜你喜欢
    • 2018-11-11
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多