【问题标题】:How the actual image size work on flutter?实际图像大小如何影响颤振?
【发布时间】:2019-02-13 13:52:54
【问题描述】:

在下图中,我的手机屏幕尺寸为 (1080x1920),屏幕上显示的图像(红色方块)为 (400x400) 像素。但是图像在设备屏幕上占据了超过 400px 的大空间。为什么flutter show会这样? Flutter 不关心实际的图像像素吗?

据我所知,在普通 (Java) android 应用程序中,它仅在屏幕上显示图像大小(如果图像大小为 72,则显示 72x72 像素),如果我们需要高分辨率屏幕的大图像,它需要创建更大尺寸的相同图像。

以下是飞镖代码。

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Image align test',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Image align test'),
        ),
        body: Container(child: Image.asset('images/pic1.png')),
      ),
    );
  }
}

【问题讨论】:

  • 尝试将图像包装成Center

标签: android dart flutter


【解决方案1】:

图像的大小由 BoxFit 决定。 Widget 本身会占用尽可能多的空间。您可以将其提供给图像(例如Image.asset('images/pic1.png',fit: BoxFit.cover)。整个枚举位于here,但您期望的可能是 Boxfit.none:

【讨论】:

    猜你喜欢
    • 2019-03-07
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多