标签小部件中的背景忽略缩放 [英] Background in tab widget ignore scaling

查看:24
本文介绍了标签小部件中的背景忽略缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

标签内容:

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

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

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

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

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

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

一些想法?

推荐答案

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

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

由于相对布局内的元素可以重叠,这应该可以工作,并且在布局中独立使用 Drawable 而不是包含作为元素 background_src 的位图可能会给您更大的灵活性.

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.

这篇关于标签小部件中的背景忽略缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆