【问题标题】:Background in tab widget ignore scaling选项卡小部件中的背景忽略缩放
【发布时间】:2010-03-09 14:02:50
【问题描述】:

我尝试为标签内容使用背景 (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,因为整个背景都是可见的,但纵横比被忽略了。

一些想法?

【问题讨论】:

    标签: android background scale android-tabhost


    【解决方案1】:

    试着把它放在RelativeLayout中而不是使用你的背景drawable:

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

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

    【讨论】:

    • 我不得不使用 ImageView 标签,但这是我需要的。现在我只需要 Android 支持一个 scaleType ,它从底部开始,如 fitEnd ,但将两个轴都缩放到父视图,如 centerCrop :) 谢谢!
    【解决方案2】:

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

    <TabHost android:background="@drawable/background">
    

    【讨论】:

    • 我试过了,结果:透明标签,我再也看不到标签图标/文本了(至少在 G2 上)
    • 我尝试将图像作为背景而不是 xml。它奏效了。
    • 这似乎可行,但在横向中,纵横比不正确,因为由于标题/通知栏,背景的高度小于显示宽度。我无法定义 scaleType 来解决此问题,因为无法缩放背景定义:/
    猜你喜欢
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多