【问题标题】:how to scale gif image to fill full screen (all sizes)如何缩放 gif 图像以填充全屏(所有尺寸)
【发布时间】:2019-01-25 23:54:38
【问题描述】:

我用gif 图像制作了一个启动页面,正如您在此布局中看到的那样:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Splash">

    <pl.droidsonroids.gif.GifImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:cropToPadding="true"
        android:scaleType="fitXY"
        android:src="@drawable/fneclis_splash_bg"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

我创建了所有布局尺寸(小、正常、大和 xlarge),并对 gif 图像(ldpi、mdpi、hdpi、xhdpi、xxhdpi 和 xxxhdpi)做了同样的事情。

我的问题是小布局采用 mdpi gif 图像大小,普通布局采用 xxhdpi 图像大小,其他布局也有同样的问题。

我想问题可能出在这里,因为它包含一些关于标题和全屏的行 这是启动代码:

package com.medanis.fneclis

import android.content.DialogInterface
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.view.ViewConfiguration
import android.view.Window
import android.view.WindowManager
import android.widget.MediaController
import pl.droidsonroids.gif.GifDrawable
import pl.droidsonroids.gif.GifImageButton

class Splash : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //hiding title bar of this activity
        window.requestFeature(Window.FEATURE_NO_TITLE)
        //making this activity full screen
       window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
        setContentView(R.layout.activity_splash)

        //2.63second splash time
        Handler().postDelayed({
            //start main activity
            startActivity(Intent(this, MainActivity::class.java))
            //finish this activity
            finish()
        },2630)


        val gib = GifImageButton(this)
        setContentView(gib)
        gib.setImageResource(R.drawable.fneclis_splash_bg)
        val mc = MediaController(this)
        mc.setMediaPlayer(gib.drawable as GifDrawable)
        mc.setAnchorView(gib)
        gib.setOnClickListener(object : DialogInterface.OnClickListener, View.OnClickListener {
            override fun onClick(p0: View?) {
                mc.show()
            }

            override fun onClick(p0: DialogInterface?, p1: Int) {
                mc.show()
            }

        })

    }
}

这可能是什么原因?请帮助我,谢谢。

【问题讨论】:

    标签: android image android-studio scale gif


    【解决方案1】:
    android:scaleType="fitXY" to android:scaleType="centerCrop"
    

    好的,因此 centerCrop 用于统一缩放图像,同时保持图像或在您的情况下保持 gif 的纵横比。而在 fitXY 的情况下,它只适合图像的父视图,不考虑纵横比。

    【讨论】:

    • 虽然此代码 sn-p 可能是解决方案,但包含解释确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
    • @rohithhammaiah 请将该评论编辑为您的答案。只有代码的答案会被自动标记为低质量的帖子审查。 From Review
    • 问题出在这里 gib.setImageResource(R.drawable.fneclis_splash_bg) 这个代码只需要一个图像大小
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多