开发者

Using repeating image to display the status bar / header for a screen

开发者 https://www.devze.com 2023-02-15 14:25 出处:网络
I have implement something like the following on J2me. Is it possible to implement the same for Android?

I have implement something like the following on J2me. Is it possible to implement the same for Android?

i> I have a strip of image which I am keeping on the drawable folder. The image width & height is small.

ii> Now , using Android code & la开发者_StackOverflowyout xml , I want to repeat displaying the small image strip so that an entire status bar / header is drawn for a screen with the use of repeating images.(mutiple image strips will ultimately draw the entire header)

The reason for implementing the header / status bar in this manner is to avoid keeping the entire header image on the drawable folder which increases the mobile application size.

Kindly provide me your inputs/sample code if anyone has done any implementation with the above logic.

Thanks in advance.


Yes, you can have tiled bitmaps in android.

If your tile is in drawable/background.png, then in drawable/background_tile.xml:

<bitmap android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/background" 
    android:tileMode="repeat"/>

And then you can set the background of a View to be your tiled bitmap in your layout:

<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="20dp"
    android:background="@drawable/background_tile"/>

You could set the background of a LinearLayout or other View subclass as well.


Two things:

1) I would strongly recommend using a nine patch if at all possible (Especially recommend at least checking out the draw9Patch tool if you havent already) Android draw9Patch info

2.) I've had issues with the tileMode xml attribute being ignored, so had to use the following code to enable the tileMode (this may have been a bug in 1.5)

/**
* Set up any UI elements
*/
private void setUpUI() {
    // Add tiling background
    View backgroundLayout = findViewById(R.id.backgroundLayout);
    BitmapDrawable bgImage = (BitmapDrawable) this.getResources().getDrawable(R.drawable.wood_bg);
    bgImage.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    backgroundLayout.setBackgroundDrawable(bgImage);
}

Code snippet taken from Gaunt Face - Where-To-Do Post

0

精彩评论

暂无评论...
验证码 换一张
取 消