活动中的全屏背景图片 [英] Full screen background image in an activity
问题描述
我看到许多使用全屏图像作为背景的应用程序.这是一个例子:
I see many applications that use a full-screen image as background. This is an example:
我想在一个项目中使用它,到目前为止我发现的最好的方法是使用大尺寸的图像,把它放在 ImageView
中并使用 android: adjustViewBounds="true"
调整边距
I want to use this in a project, the best way I've found so far to do this is to use an image with a large size, put it in a ImageView
and use android: adjustViewBounds="true"
to adjust the margins
问题是,如果屏幕的分辨率非常高,图像就会不够.
The problem is that if a screen with a very high resolution, the image falls short.
我想到的另一个选择是在 FrameLayout
中使用图像,在 width
和 height
中使用 match_parent
> 作为背景...这样可以拉伸图像,但我认为效果不是很好.
Another option I thought of is to use the image in a FrameLayout
, with match_parent
in width
and height
as background... this stretches the image, but I think the result is not very good.
你会怎么做?
推荐答案
有几种方法可以做到.
选项 1:
为不同的dpi创建不同的完美图像并将它们放在相关的drawable文件夹中.然后设置
Create different perfect images for different dpi and place them in related drawable folder. Then set
android:background="@drawable/your_image"
选项 2:
添加单个大图像.使用框架布局.作为第一个孩子添加 ImageView
.在您的 ImageView 中设置以下内容.
Add a single large image. Use FrameLayout. As a first child add an ImageView
. Set the following in your ImageView.
android:src="@drawable/your_image"
android:scaleType = "centerCrop"
这篇关于活动中的全屏背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!