gpt4 book ai didi

java - 如何在我的 Android 应用程序中实现 GIF?

转载 作者:行者123 更新时间:2023-12-02 06:08:44 25 4
gpt4 key购买 nike

嘿,我是 Android 编程新手。我想知道如何在我的 Android 应用程序中轻松实现 GIF。

我必须做什么?

我尝试过这个,但我做错了。它不起作用。 >>THIS<<

最佳答案

基本上,我给您提供以下示例,该示例从某个网站在线加载图像并在一段时间后每次更改它。

public class Gif_First extends Activity {

WebView mWebView;
int i = 0;
CountDownTimer mTimer;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.animation);

mTimer = new CountDownTimer(15000, 1000) {
private String[] myArray = {
"http://i.share.pho.to/09d99399_o.gif",
"http://i.share.pho.to/220dd194_o.gif",
"http://i.share.pho.to/6f3a5ae4_o.gif",
"http://i.share.pho.to/1b264cb7_o.gif",
"http://i.share.pho.to/824b1aab_o.gif",
"http://i.share.pho.to/c6728fb8_o.gif",
"http://i.share.pho.to/5508a2e1_o.gif",
"http://i.share.pho.to/aa64f9a9_o.gif",
"http://i.share.pho.to/d4619e93_o.gif",
"http://i.share.pho.to/2d50de0a_o.gif",
"http://i.share.pho.to/23c030eb_o.gif",
"http://i.share.pho.to/d6e3ccad_o.gif",
"http://i.share.pho.to/eaaeaf88_o.gif",
"http://i.share.pho.to/9708dd88_o.gif",
"http://i.share.pho.to/7f879974_o.gif",
"http://i.share.pho.to/efe8afa3_o.gif",
"http://i.share.pho.to/259954ac_o.gif",
"http://i.share.pho.to/bdbc28f2_o.gif" };
int currentIndex = 0;

public void onTick(long millisUntilFinished) {
}

public void onFinish() {
if (currentIndex < myArray.length) {
mWebView.loadUrl(myArray[currentIndex]);
currentIndex++;
} else {
currentIndex = 0;
if (currentIndex < myArray.length)
mWebView.loadUrl(myArray[currentIndex]);
currentIndex++;
mTimer.start();
}
mTimer.start();
}
// code comment end
};

mTimer.start();
mWebView = (WebView) findViewById(R.id.webviewActionView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://i.share.pho.to/49cf97de_o.gif");
mWebView.setWebViewClient(new WebSliderWebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(mWebView, url);
//Toast.makeText(getApplicationContext(), "Done!",
// Toast.LENGTH_SHORT).show();

}

@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
//Toast.makeText(getApplicationContext(),
// "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

private class WebSliderWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}

这是 XML 文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/DogView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >

<WebView
android:id="@+id/webviewActionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

我认为所有链接都已失效,但您可以在那里上传一些图像并更改链接,然后尝试。

关于java - 如何在我的 Android 应用程序中实现 GIF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22062373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com