K
K
Kirill Sidorov2015-01-05 21:35:18
Android
Kirill Sidorov, 2015-01-05 21:35:18

How to correctly fill the background with a picture in Andoid?

c9a0919cdc9143ad816617c00b5f86ab.png
I'm trying to make such a title bar. Right now it's organized like this: LinearLayout with a background that is a bitmap.
Layout piece:

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/linearLayout"
        android:background="@drawable/header_bg"
        android:gravity="center_horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="ЗАКАЗ ТАКСИ"
            android:id="@+id/textView5"
            android:background="#f9d25e"
            android:gravity="center_vertical|center_horizontal"
            android:textStyle="bold"
            android:textColor="#000"
            android:textSize="20sp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" />

    </LinearLayout>

header_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/header_app"
    android:tileMode="repeat"
    android:dither="true" />

where @drawable/header_app is a 20x80px PNG
Question two:
  1. Is such a plate correctly laid out? I'm new to the web, maybe I'm still thinking at the HTML level.
  2. How to work with images with different pixel densities on the display? Now in Design mode, when designing a layout, it looks like in the screenshot above, when launched on the emulator, the image is displayed in half size. If header_app.png is reduced to 10x40, then everything is fine in the emulator, but when designing, I see a picture tiled vertically and horizontally (MBP Retina)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
one pavel, 2015-01-06
@cyberia

There was a similar task, I would transfer the checkered background to 9patch developer.android.com/tools/help/draw9patch.html
you then get rid of android:tileMode="repeat"
and you need to look at what resolution your picture,
developer.android. com/guide/practices/screens_supp...

A
Aleksadar Angelov, 2015-01-06
@Aleksadar

Caco

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question