作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 WebView
中显示一个 gif 文件。
在我的网页完成加载之前,此 gif 是可见的。
我是通过以下方式来做的:
我已将 loading.gif
放在 asset
文件夹中。
xml:
<WebView
android:id="@+id/webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_centerHorizontal="true"/>
Java:
wv.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
WebView loading = (WebView)findViewById(R.id.webview1);
loading.loadUrl("file:///android_asset/loading.GIF");
loading.setBackgroundColor(Color.TRANSPARENT);
loading.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
WebView loading = (WebView)findViewById(R.id.webview1);
loading.setVisibility(View.INVISIBLE);
}
});
xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/frame1" android:duration="50" />
<item android:drawable="@drawable/frame2" android:duration="50" />
<item android:drawable="@drawable/frame3" android:duration="50" />
etc...
</animation-list>
Java:
imageView.setBackgroundResource(R.drawable.movie);
AnimationDrawable anim = (AnimationDrawable) imageView.getBackground();
anim.start();
但是两种情况下动画都不流畅。不过第二种方法更好。我只想知道没有gif有没有办法达到同样的效果?如果那不可能的话,我想知道 gif 在所有像素密度下是否具有相同的大小。因为 gif 文件的尺寸是 px
而不是 dp
。
最佳答案
这是一个例子
WebView
使用 .gif 文件的地址创建 html:
<html style="margin: 0;">
<body style="margin: 0;">
<img src="https://..../myimage.gif" style="width: 100%; height: 100%" />
</body>
</html>
将此文件存储到 Assets 目录中:
将此 html 加载到应用程序的 WebView
中:
WebView webView = (WebView)findViewById(R.id.webView);
webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("file:///android_asset/html/webpage_gif.html");
这是一个complete example with two options (using WebView or ImageView) to load an animated gif .
关于android-在webview中加载gif动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32257431/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!