【问题标题】:Animated Splash screen Android动画启动画面 Android
【发布时间】: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


【解决方案1】:

您选择了错误的比例类型,将 scaleType 设置为 FitXY 而不是 fit center 但当然它会导致改变比例,看看它是否有类似 centerCrop 比例的东西。

<com.felipecsl.gifimageview.library.GifImageView
    android:id="@+id/gifImageView"
    android:scaleType="fitXY"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

【讨论】:

  • 你能告诉我你为什么在回答中使用marginRight="0dp"marginLeft="0dp" 吗?
  • @Charuka 只是为了澄清,它与 none 相同
猜你喜欢
  • 2021-12-26
  • 1970-01-01
  • 2020-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-21
  • 2020-06-15
相关资源
最近更新 更多