繁体   English   中英

Android App背景图片填充高度但不是宽度

[英]Android App background image fill height but not width

我正在尝试将背景图像添加到视图中。 图像真的很宽,不是那么高。 它是6400 x 480.我希望图像填满Android屏幕的高度并保持它的纵横比。 我似乎无法让这个工作。

<ImageView
    android:id="@+id/background"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/background"
    android:scaleType="fitStart"
    android:layout_alignParentBottom="true" />

请记住,我已尝试使用scaleType的所有选项,它只是没有给出所需的效果。 我希望能够将图像向左移动,以便稍后显示图像的其余部分。

任何建议,提示都会很棒! 也许我会以错误的方式解决这个问题。

我自己最终找到了解决方案。 我在drawables文件夹中创建了一个名为background.xml的XML文件,并将此代码放入其中:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/background_image"
    android:tileMode="disabled" android:gravity="top|left|fill_vertical">
</bitmap>

其中创建了一个位图对象供使用。 然后我将这个android:background="@drawable/background"添加到我的main.xml中的RelativeLayout标签中。

工作就像一个魅力

暂无
暂无

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

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