簡體   English   中英

標簽小部件中的背景忽略縮放

[英]Background in tab widget ignore scaling

我試圖將背景(480x320)用於標簽內容。 使用xml作為可繪制對象,我應該能夠縮放圖像。 在tabhost / tabactivity之外可以正常工作。 如果嘗試在tabcontent內使用它,則scaleType不起作用。 他忽略了我嘗試過的每個scaleType。

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>

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,因為整個背景都是可見的,但寬高比卻被忽略了。

有什么想法嗎?

嘗試僅將其放置在RelativeLayout中,而不使用背景可繪制對象:

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

由於relativelayout內的元素可以重疊,因此這應該可行,並且在布局中獨立使用Drawable而不是作為background_src元素包含的位圖可以為您提供更大的靈活性。

將背景設置為不在tabcontent布局中的ur tabhost標記。 那是

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM