【问题标题】:Webview display .gif at centerWebview 在中心显示 .gif
【发布时间】:2014-08-24 11:52:23
【问题描述】:

我在 webview 中显示一个 .gif。有用!。但它显示在左侧。我需要显示在中心。

  View footerView =  ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listviewfooter, null, false);
    webviewLoadmore = (WebView) footerView.findViewById(R.id.webviewLoadmore);
    webviewLoadmore.loadUrl("file:///android_asset/load_icon.gif");

之后我将它添加到 Listview 页脚中。

clubListView.addFooterView(webviewLoadmore);

我的 xml 布局

<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webviewLoadmore"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:scrollbars="none" 
     android:scaleType="centerInside"
    >
</WebView>

【问题讨论】:

  • 试试 android:gravity="center"
  • 这不是 webview 的属性
  • 哦,对不起,我的意思是布局

标签: android webview gif


【解决方案1】:

将 Gif 放在 HTML 文件中并对其进行编码,就像图像将显示在网页的中心一样(显然使用 css)。然后在 WebView 中加载 html 页面。

更多详情请查看here

【讨论】:

  • 将 html 放在 assets 中并使用 loadUrl() 加载它,就像你为 gif 所做的那样。
  • 它正在向我显示你好字。但不是 gif 图片。
  • 伙计,您只是复制粘贴了该代码。更改 html 正文以显示您的图像。它必须类似于
  • 它没有显示图像。只显示一个图标而不是 gif 图像
【解决方案2】:

试试这个:

WebView web = (WebView) findViewById(R.id.gif_image);
web.getSettings().setDefaultZoom(ZoomDensity.FAR);

或者:

public void loadImage(){
   Bitmap BitmapOfMyImage=BitmapFactory.decodeResource(Environment.getExternalStorageDirectory()
                                       .getAbsolutePath()+"yourFolder/myImageName.jpg");  

   mWebView.loadDataWithBaseURL("file:///"+Environment.getExternalStorgeDirectory()  
                               .getAbsolutePath()
                                +"yourFolder/","<html><center>
                                <img src=\"myImageName.jpg\" vspace="
                                +(currentHeight/2-(BitmapOfMyImage.getHeight()/2))+">
                                 </html>","text/html","utf-8","");
 //This loads the image at the center of thee screen                    
}

【讨论】:

    猜你喜欢
    • 2016-04-09
    • 2011-06-17
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 2013-08-22
    • 2010-11-30
    相关资源
    最近更新 更多