Android layouts - background image offset in xml

I have a big png that I would like to use as a background for different layouts, but I shift it so that I can have different parts showing (as you can in CSS), preferably in xml.

In my main layout for work there is the following xml:

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/bg1">

Layout bg1 consists of the following 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" />

The gravity property works as expected, but fields and paddings are ignored, apparently because I'm working on a raster object, not a layout. What I want to do is set them to minus to show only part of the image. I tried using a shape, but only wrap the contents, while I need to fill the whole background.

Any suggestions would be greatly appreciated. Thank.

+3
2

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>
+5

InsetDrawable ( XML), .

+2

Source: https://habr.com/ru/post/1786902/


All Articles