android ImageView src属性不支持.9图

  今天碰到一个问题:对ImageView的src属性设置.9图片时,无论怎么设置其高与宽,显示的仍然是.9图的原始大小。

<ImageView

    android:layout_width="10dp"

    android:layout_height="80dp"

    android:src="@drawable/fixed_divider_horizontal_bright" >

在此处的fixed_divider_horizontal_bright是张.9图片,通过查资料才知道ImageView的src属性在没有设置android:scaleType="fitXY"时,是不会按照设定的高宽拉伸的;

解决方法就有很多了:

1 很显然就是加上android:scaleType="fitXY"属性就行了;改完之后的代码

<ImageView

    android:layout_width="10dp"

    android:layout_height="80dp"

    android:scaleType="fitXY"

    android:src="@drawable/fixed_divider_horizontal_bright" >

2 使用android:background属性代替android:src,不用设置android:scaleType属性

<ImageView

    android:layout_width="10dp"

    android:layout_height="80dp"

    android:background="@drawable/fixed_divider_horizontal_bright" >

3 使用View代替ImageView

<View

    android:layout_width="10dp"

    android:layout_height="80dp"

    android:background="@drawable/fixed_divider_horizontal_bright" >

这种方法对于一定要使用ImageView控件的场景中是不行的

 

参考:1 http://stackoverflow.com/questions/5242880/android-9-patch-graphic-doesnt-scale-in-image-view

 

====================================================================== 
声明: 转载请注明出处

你可能感兴趣的:(imageview)