如何覆盖imageview在Webview android上

时间:2012-10-30 11:26:54

标签: android android-layout webview imageview

我是android的初学者。我想在webview上叠加图像。我使用带有webview和imageview的Framelayout。它工作正常。但是,当在webview中播放视频时,不会显示图像。如何在播放器中显示图像?我在下面提到了我的代码。请帮帮我

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:layout_margin="0dp">

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="0dp"
    android:padding="0dp" 
    android:scaleType="center"/>

 <ImageView
     android:id="@+id/imageview"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="center_horizontal|center"
     android:contentDescription="@string/webviewexample"
     android:src="@drawable/image"/>

</FrameLayout >

1 个答案:

答案 0 :(得分:0)

您好我甚至在webview上保留了几个按钮图像和进度条。这是代码片段。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical">

    <WebView
        android:id="@+id/myWebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="80dip"
        android:src="@drawable/homepageheader"
        android:layout_marginTop="0dip" />

   <ImageButton
        android:id="@+id/button_back"
        android:layout_width="36dp"
        android:layout_height="44dp"
        android:layout_marginLeft="20dip"
        android:background="@android:color/transparent"
       android:layout_marginTop="22dip"
        android:src="@drawable/backbtn" /> 

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal" />

 <ImageButton
       android:id="@+id/button_refresh"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/refresh_icon" 
        android:layout_gravity="right"
        android:layout_marginRight="20dip"
        android:layout_marginTop="22dip"
        android:background="@android:color/transparent"/> 

</FrameLayout>

但是,这可以通过使用“接口”构建器来实现。

首先将webview拖放到布局文件中。

稍后尝试添加图像或图像按钮。

希望这有帮助。