2014-07-05 55 views
0

我已经阅读了多篇文章,了解如何在ImageView上显示WebView。以下是我最后一次尝试,它仍然无法正常工作:通过ImageView Android的WebView Android

mPhotoWebView.setWebViewClient(new WebViewClient()); 
mPhotoWebView.setBackgroundColor(0x00000000); 

XML:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="300dp" > 

    <com.example.android.views.MyImageView 
     android:id="@+id/photoImageView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <WebView 
     android:id="@+id/photoWebView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbarStyle="insideOverlay" 
     android:scrollbars="none" /> 

HTML样式:

body 
{ 
    background:transparent; 
    background-color: rgba(10,10,10,0.5); 
} 

此代码需要在4.2.2运行。我试图完成的是,webview在html5中完成了动画代码,imageView是动画需要显示的背景图片。

任何想法?

+0

我终于得到了这个工作。见下面的答案。 – taraloca

回答

0

我以前一定错过了这个组合。我的最终解决方案是:

不要在代码中将背景颜色设置为webView。

body 
    { 
     background:transparent; 
     overflow: hidden; 
     background-color: rgba(10,10,10,0.5); 
    } 

XML:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="300dp" > 

    <com.accuweather.android.views.MyImageView 
     android:id="@+id/photoImageView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <WebView 
     android:id="@+id/photoWebView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/transparent" 
     android:layerType="software" 
     android:scrollbarStyle="insideOverlay" 
     android:scrollbars="none" /> 

这里的关键是软件layerType。我正在使用一个活动处理很多的片段,所以我无法在清单中执行此操作。因此我在xml中这样做了。