2016-12-05 209 views
0

我最近做了一些关于android drawable的测试,我发现android:src行为对于padding来说是非常奇怪的,比较android:background。为什么android:src在drawable中的填充行为很奇怪?

这里是我的绘制:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item> 
      <shape android:shape="oval"> 
       <solid android:color="@color/colorAccent"/> 
       <padding 
        android:top="1dp" 
        android:right="1dp" 
        android:bottom="1dp" 
        android:left="1dp" 
        /> 
      </shape> 
     </item> 
     <item android:top = 2> 
      <shape android:shape="oval"> 
       <solid android:color="@color/white"/> 

      </shape> 
     </item> 
</layer-list> 

内部在MainActivity布局我有我用来测试其他图像视图。我将图像视图设置为40dp的宽度和高度。然后通过将它们设置为我上面的drawable来测试android:src与android:background属性。下面是结果:

安卓:SRC

enter image description here

安卓背景

enter image description here

了Android:背景,你可以看到的是预期的行为,因为我谨白向下滚动2,并且它具有服从粉红色椭圆形填充的填充。现在android:src是直线上升的,因为没有显示第一个白色椭圆,它是粉红色椭圆上方的图层。其次,形状变成扁平的椭圆形。

任何线索为什么这是这种情况??????

回答

1

src作品与android:scaleType在那里你可以给不同的选项ScaleType

而背景总是需要的FitXY scaleType覆盖全区域的这一观点。

如果你想相同的行为背景SRC

放机器人:scaleType = “FitXY”。还有其他的选择你也应该检查。