【问题标题】:Image is pixelated and streched when SpalshScreenActivity is created创建启动画面活动时图像被像素化和拉伸
【发布时间】:2021-05-11 19:33:27
【问题描述】:

这是我的初始屏幕活动,然后指向我的主要活动

 public class SplashScreenActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
            finish();
        }
    }

下面是我的启动画面 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <item android:drawable="@android:color/holo_purple" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/blogger"
            />
    </item>
</layer-list>

我尝试改变重力属性,但没有任何改变。下面的截图是拉伸的图像

【问题讨论】:

  • 你应该使用 Imageview 和属性 scaleType centerCrop
  • 我尝试使用带有 centerCrop 属性的图像视图
  • 为什么要全屏使用徽标
  • 设置宽高
  • 宽度和高度也不起作用。它应该是在主要活动准备启动时调用的启动画面。

标签: android screen splash-screen


【解决方案1】:

仅 API 23 或更高版本

随便用

<item
    android:width="200dp"
    android:height="200dp"
    android:drawable="@drawable/splash_background"
    android:gravity="center" />

改为

<item
    android:left="200dp"
    android:right="200dp">

    <bitmap
        android:src="@drawable/splash_background"
        android:gravity="center" />

</item>

或者使用 ImageView

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="center"
android:src="@drawable/Icon" />

【讨论】:

  • 我正在使用 API 23 + 并且我正在以适当的方式实现我的启动画面。此外,我的位图有不同的大小 xxhpi、hdpi,但仍然让我很难找出解决方案。
猜你喜欢
  • 2021-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多