1

我尝试为标签内容使用背景 (480x320)。使用 xml 作为可绘制对象,我应该能够缩放图像。这在 tabhost/tabactivity 之外工作正常。如果我尝试在 tabcontent 中使用它,则 scaleType 不起作用。他忽略了我尝试过的每一个 scaleType。

标签内容:

<?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>

res/drawable 中的 background.xml

<?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"/>

当然,我通过更改图像检查了 xml 是否真的被使用,在图像更改时使用了 xml。

使用的缩放比例似乎是 fitXY,因为整个背景都是可见的,但纵横比被忽略了。

一些想法?

4

2 回答 2

2

尝试将其放置在 RelativeLayout 中,而不使用您的背景可绘制对象:

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

由于 relativelayout 中的元素可以重叠,这应该可以工作,并且在布局中独立使用 Drawable 而不是作为元素 background_src 包含的 Bitmap 可能会给您更多的灵活性。

于 2010-03-09T15:00:56.570 回答
1

将背景设置为您的 tabhost 标签,而不是在 tabcontent 布局中。那是

<TabHost android:background="@drawable/background">
于 2010-03-09T14:33:31.593 回答