我有一个大的png,我想用它作为不同布局的背景,但是偏移它以便我可以有不同的部分显示(很像你可以在CSS中),最好是在xml中. 我的活动主要布局包含以下xml: LinearLayoutandroid:layout_width="
我的活动主要布局包含以下xml:
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@layout/bg1">
布局bg1由以下xml组成:
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns: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>