2011-05-02 123 views
0

我正在設計一個佈局,我將以位圖爲中心,並且我想要左邊的&右邊距位圖縮放(水平)以填充屏幕,以便我的中心項目可以是一個裝飾的標題欄,左邊的&右邊是與中心位圖背景匹配的填充位圖,因此水平延伸。Android視圖佈局縮放位圖

但我所看到的是位圖之間有一個空格。左邊的&右邊的比例尺,但它們之間有一個空間。

如什麼,我得到的是:
http://www.58seconds.com/getting.png

我要的是:
http://www.58seconds.com/want.png

任何想法?

這裏是佈局的代碼,我使用的一個片段:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 
<ImageView 
    android:layout_width="1dp" 
    android:layout_weight="1" 
    android:layout_height="45sp" 
    android:src="@drawable/mdjleftfiller" 
    android:layout_gravity="top" 
    android:gravity="top" 
    android:scaleType="fitXY" 
    /> 
<ImageView 
    android:id="@+id/command_selection_topImage" 
    android:layout_width="wrap_content" 
    android:layout_height="45sp" 
    android:src="@drawable/top_image" 
    android:layout_gravity="top" 
    android:gravity="top" 
    android:layout_weight="0" 
    /> 
<ImageView 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:layout_height="45sp" 
    android:src="@drawable/mdjrightfiller" 
    android:layout_gravity="top" 
    android:gravity="top" 
    android:scaleType="fitXY" 
    /> 
</LinearLayout> 

回答

1

你有沒有想過用你的單個標題欄圖像創建一個9補丁?如果您在實際標題的任何一邊都有「延伸」部分,則它會根據您的需要進行拉伸以適應您的需求,而無需藉助佈局欺騙。

+0

是的,9貼片PNG是很好的解決方案。謝謝。 – Cris 2011-10-12 17:52:08

0

嘗試創建兩個圖像,一個作爲背景,scaleType到FIT_CENTER,然後將另一根躺在上面,只是移到中央。

0

這裏是這樣做的一個很好的清潔方式,這是相當多正是盧卡斯在說什麼,但在XML中:

<FrameLayout android:id="@+id/navbar" android:layout_width="fill_parent" android:layout_height="wrap_content"   android:background="@drawable/titlebar_repeat"> 
    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/titlebar_logo" android:layout_gravity="center" /> 
</FrameLayout> 

在這種情況下titlebar_repeat只是單個像素寬,titlebar_logo只是具有透明背景的文字。在你的情況下,因爲你似乎並不想要高度風格化的文本,所以如果你喜歡,你可以將ImageView改爲TextView。

+0

這是很好的答案,9貼片PNG也不錯。謝謝。 – Cris 2011-10-12 17:52:14