2011-05-02 99 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