1、先导入pl.droidsonroids.gif:android-gif-drawable:1.2.3.jar包
2、
3、
public class MainActivity extends AppCompatActivity {
private Activity mActivity;
private GifImageView gif_splash;
private LinearLayout lly_button;
private TextView tv_enter_game,tv_attention;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//只能竖屏
mActivity = this;
init();
}
private void init() {
gif_splash = (GifImageView) mActivity.findViewById(R.id.gif_splash);
lly_button = (LinearLayout) mActivity.findViewById(R.id.lly_button);
tv_enter_game= (TextView) mActivity.findViewById(R.id.tv_enter_game);
tv_attention= (TextView) mActivity.findViewById(R.id.tv_attention);
// 设置背景gif图片资源
gif_splash.setImageResource(R.drawable.splash);
final GifDrawable getDura=GifDrawable.createFromResource(getResources(),R.drawable.splash);
int duration=getDura.getDuration();
Log.e("url","duration=="+duration);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
lly_button.setVisibility(View.VISIBLE);
getDura.stop();
return;
}
});
}
}, duration);
}
}
有错误欢迎指正,谢谢~