Android 背景图片填充屏幕
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10679366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android background Image to fill screen
提问by kmb64
How do I get my relative layout to display my image view like this:
如何让我的相对布局像这样显示我的图像视图:
Instead of this?:
而不是这个?:
I want my layout to display as much of the image as it can and crop the outsides of the image, like when you're setting desktop background image to "Fill" in windows:
我希望我的布局尽可能多地显示图像并裁剪图像的外部,例如在 Windows 中将桌面背景图像设置为“填充”时:
My xml layout so far:
到目前为止我的 xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>
<LinearLayout
android:id="@+id/linearLayout1"
style="@style/SessionResumeBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/home_resumeSessionBar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/home_resumeSessionBar_buttonResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resume" />
</LinearLayout>
</RelativeLayout>
采纳答案by Phobos
回答by jeet
Set the ImageView
layout parameters to match_parent
and set scale type to an appropriate scale type which fulfills your needs:
将ImageView
布局参数match_parent
设置为,并将比例类型设置为满足您需求的适当比例类型:
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>
回答by Trikaldarshi
Set scalexy = true
in ImageView
设置scalexy = true
在ImageView