Background in tab widget ignore scaling
Asked Answered
H

2

1

I tried to use a background (480x320) for my tab content. Using a xml as drawable, I should be able to scale the image. This works fine outside the tabhost/tabactivity. If I try to use it inside the tabcontent, the scaleType doesn't work. He ignores every scaleType I tried.

tabcontent:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background">

    <include layout="@layout/main_list" />
</RelativeLayout>

background.xml in res/drawable

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/background_img"
    android:scaleType="centerInside"/>

Of couse I checked if the xml is really used by changing the image, at the image changed so the xml is used.

The used scaling seems to be fitXY, because the whole background is visible but the aspect ration is ignored.

Some ideas?

Housen answered 9/3, 2010 at 14:2 Comment(0)
C
2

Try just placing this inside the RelativeLayout and not using your background drawable:

<Drawable 
    android:src="@drawable/background_img" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:scaleType="fitCenter" />

Since elements inside the relativelayout can overlap, this oughta work, and using a Drawable in the layout independently instead of a Bitmap included as the element background_src might give you more flexibility.

Conoid answered 9/3, 2010 at 15:0 Comment(1)
I had to use the ImageView tag, but it is what I need. Now I only need Android to support a scaleType which starts at the bottom like fitEnd but scale both axis to the parent view like centerCrop :) Thank you!Housen
H
1

set the background to ur tabhost tag not in tabcontent layout. that is

<TabHost android:background="@drawable/background">
Hoffmann answered 9/3, 2010 at 14:33 Comment(3)
I tried this, result: transparent tabs and I can't see the tab icons/text anymore (at least at the G2)Housen
i tried just with the image as background not xml. it worked.Hoffmann
That seems to work, but in landscape the aspect ratio is not correct, because the height for the background is smaller then the display width because of the title/notification bar. I can't define a scaleType to fix this, because a background definition can't be scaled :/Housen

© 2022 - 2024 — McMap. All rights reserved.