Android - 背景底部

时间:2012-06-06 20:12:58

标签: android image layout background

我想要一个Android应用程序,其背景图像位于视图的底部。 希望这可以通过仅使用XML来实现。

我的背景图片(bg.png)位于“res / drawable-mdpi”文件夹中。 XML代码现在是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/bg"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="0dip" />
</LinearLayout>

但这会在整个页面上拉伸整个图像。我只希望它在水平方向上伸展。 高度必须与(拉伸)宽度成比例。 此图片必须是视图/布局的背景,我想继续使用布局并向其添加项目/对象。

我希望有人可以帮我这个,我一直在网上寻找它几个小时,我找不到比现在更有帮助的东西了。

提前致谢,

丹尼斯

2 个答案:

答案 0 :(得分:0)

首先将LinearLayout更改为RelativeLayout(android:layout_alignParentBottom仅适用于RelativeLayout)。

其次在你的ImageView上使用android:src =“@ drawable / bg”(不是背景)

答案 1 :(得分:0)

如果您真的想使用LinearLayout,可以尝试将此属性添加到您的imageview android:layout_gravity="bottom"

相关问题