简体   繁体   English

Android图片缩放

[英]Android Images scaling

I always have problems when using images. 使用图像时我总是会遇到问题。 I want to use an image as splash screen. 我想使用图像作为初始屏幕。 So I imported all resolutions (ldpi to xxhdpi) of my image using Multisource-Drawable in Android Studio. 因此,我使用Android Studio中的Multisource-Drawable导入了图像的所有分辨率(从ldpi到xxhdpi)。 Then, I created a imageview in my Activity and set Width and Height to 150dp both. 然后,我在Activity中创建了一个imageview,并将Width和Height都设置为150dp。 It seems to use the ldpi resource and the image get very blurry. 似乎使用了ldpi资源,图像变得非常模糊。

What's the best way to import images in Android Studio to general use? 在Android Studio中将图像导入一般用途的最佳方法是什么?

[UPDATE] [更新]

Android is chosing the right size, but not how I want. Android选择合适的尺寸,但不是我想要的尺寸。 I fixed it by adding a 512x512 png file and then setting its Width And Height to 150dp 我通过添加512x512 png文件然后将其宽度和高度设置为150dp来修复它

I think your question may have two separate answers. 我认为您的问题可能有两个单独的答案。 First, you are assuming that an image is the best way to set up a splash screen. 首先,您假设图像是设置初始屏幕的最佳方法。 This is not so, as the content would have to be called after the app has already finished setting up. 事实并非如此,因为必须在应用程序完成设置调用内容。 That would mean your user sees a flash (or more) of a blank screen before the splash screen is shown. 这意味着您的用户会在显示初始屏幕之前看到黑屏的闪烁(或更多)。 Second, you would like to know the best way to import images into Android Studio. 其次,您想知道将图像导入Android Studio的最佳方法。 Here are the two different answers: 这是两个不同的答案:

#1 The best way to implement a splash screen is to have a theme called on a blank activity. #1实施启动屏幕的最佳方法是在空白活动中调用一个主题。 The theme would include your desired image and background color. 主题将包括您想要的图像和背景色。 The reason for this is to eliminate the short break before content is called. 这样做的原因是为了消除在调用内容之前的短暂中断。 Click here for a link describing more and giving a tutorial. 单击此处以获得更多描述并提供教程的链接。

#2 In my opinion, the simplest and most robust way to add an image resource is to use the Image Asset import feature. #2我认为添加图像资源的最简单,最可靠的方法是使用图像资产导入功能。 Follow these steps: 跟着这些步骤:

  1. Right click on " res " (in the Project View) -> New -> Image Asset 右键单击“ res ”(在项目视图中)->“ 新建” ->“ 图像资产”
  2. On Icon Type choose Action Bar and Tab Icons 在图标类型上,选择操作栏和选项卡图标
  3. For Asset Type choose Image 对于资产类型,选择图像
  4. Choose the image path (on your computer) 选择图像路径(在计算机上)
  5. Give your image a name (no UPPERCASE, only lowercase and underscores, etc) 给您的图片起一个名字(不要大写,只能是小写和下划线等)
  6. Next -> Finish 下一个 -> 完成

使图像视图的高度和宽度wrap_content并将其重力设置为中心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM