Android布局 – 在xml中偏移背景图像

Android布局 – 在xml中偏移背景图像,第1张

概述我有一个大的png,我想用它作为不同布局的背景,但是偏移它以便我可以有不同的部分显示(很像你可以在CSS中),最好是在xml中. 我的活动主要布局包含以下xml: <LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@layout/bg1"> 我有一个大的png,我想用它作为不同布局的背景,但是偏移它以便我可以有不同的部分显示(很像你可以在CSS中),最好是在xml中.

我的活动主要布局包含以下xml:

<linearLayoutandroID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:background="@layout/bg1">

布局bg1由以下xml组成:

<?xml version="1.0" enCoding="utf-8"?><bitmapxmlns:androID="http://schemas.androID.com/apk/res/androID"androID:src="@drawable/big_image"androID:layout_margintop="50sp"androID:paddingtop="50sp"androID:gravity="top|left" />

gravity属性按预期工作,但边距和填充被忽略,可能是因为我正在处理位图对象而不是布局.我想要做的是将它们设置为负数,以便只显示部分图片.我尝试过使用一个形状,但只包含内容,而我需要填充整个背景.

我们将非常感激地收到任何建议.谢谢.

解决方法 我使用了具有负上边距值的ImageVIEw. ImageVIEw首先在布局中声明,因此它在控件堆栈中最低,并且将在其他控件后面呈现.

<relativeLayout    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent">    <ImageVIEw        androID:ID="@+ID/biglogo"        androID:src="@drawable/big_logo"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParenttop="true"            androID:layout_margintop="-100px" /></relativeLayout>
总结

以上是内存溢出为你收集整理的Android布局 – 在xml中偏移背景图像全部内容,希望文章能够帮你解决Android布局 – 在xml中偏移背景图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1121757.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存