【发布时间】:2017-01-27 11:31:21
【问题描述】:
我想在初始屏幕上以全尺寸显示我的动画 gif 图像,但它不起作用。我还使用了match parent。这里有什么问题?我的 xml 文件是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_splashscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.foodie.splash.splashscreen">
<com.felipecsl.gifimageview.library.GifImageView
android:id="@+id/gifImageView"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_marginRight="0dp"
android:layout_marginLeft="0dp"
android:layout_height="match_parent" />
</RelativeLayout>
这就是它的外观:
Java 代码:
package com.example.foodie.splash;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import com.felipecsl.gifimageview.library.GifImageView;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
public class splashscreen extends AppCompatActivity {
private GifImageView gifImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
gifImageView = (GifImageView)findViewById(R.id.gifImageView);
//Set GIFImageView resource
try{
InputStream inputStream = getAssets().open("foodie.gif");
byte[] bytes = IOUtils.toByteArray(inputStream);
gifImageView.setBytes(bytes);
gifImageView.startAnimation();
}
catch (IOException ex)
{
}
//Wait for 3 seconds and start Activity Main
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
splashscreen.this.startActivity(new Intent(splashscreen.this,MainActivity.class));
splashscreen.this.finish();
}
},5000); // 3000 = 3second
}
}
【问题讨论】:
-
我希望这个 gif 像 intro.pls 帮助一样显示在整个页面中。
-
在您将 gif 设置为 gifView 的位置显示您的 java 代码
-
@somumkhan :尝试 android:scaleType="FIT_XY" 而不是 android:scaleType="fitCenter"
-
Rishabh Mahatha 我在上面附加了 java 文件。看看那个。谢谢。
-
android:scaleType="fitCenter"remove it 使用 CENTER 缩放图像developer.android.com/reference/android/widget/…
标签: android