2016-02-01 13 views
0

我试图使用图层列表定义XML中的自定义按钮图形,以避免向该项目添加更多位图。 我有这样的:应用于按钮时图层列表中的图像不一样

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<item android:id="@+id/tester" 
    > 
    <rotate 
     android:pivotX="20%" 
     android:fromDegrees="-45" 
     > 
      <shape 
       android:shape="rectangle"> 
       <solid 
        android:color="#000000" 
        > 
       </solid> 
       <size 
        android:height="200dp" 
        android:width="200dp" 
        > 
       </size> 
      </shape> 
    </rotate> 
</item> 

<item android:id="@+id/tester" 
    > 
    <rotate 
     android:pivotX="20%" 
     android:fromDegrees="45" 
     > 
     <shape 
      android:shape="rectangle"> 
      <solid 
       android:color="#000000" 
       > 
      </solid> 
      <size 
       android:height="200dp" 
       android:width="200dp" 
       > 
      </size> 
     </shape> 
    </rotate> 
</item> 

<item> 
<rotate 
    android:pivotX="90%" 
    android:fromDegrees="270" 
    > 
    <shape 
     android:shape="rectangle" 
     > 
     <solid 
      android:color="#000000" 
      > 
     </solid> 
     <size 
      android:width="50dp" 
      android:height="100dp" 
      > 
     </size> 

    </shape> 

</rotate> 

<item> 
    <rotate 
     android:pivotX="90%" 
     android:fromDegrees="90" 
     > 
     <shape 
      android:shape="rectangle" 
      > 
      <solid 
       android:color="#000000" 
       > 
      </solid> 
      <size 
       android:width="50dp" 
       android:height="100dp" 
       > 
      </size> 

     </shape> 

    </rotate> 
</item> 

它创建这一形象: sorry for the giant size

而且我用这个将其设置为一个按钮:

 <Button 
     android:layout_width="15dp" 
     android:layout_height="fill_parent" 
     android:id="@+id/picture_inflator" 
     android:layout_toLeftOf="@id/picture_fragment" 
     android:layout_above="@+id/button" 
     android:layout_below="@+id/title" 
     android:background="@drawable/rightButton" 
     android:layout_marginLeft="4dp" 

     /> 

但这在按钮创建图像是这样的: enter image description here

我不知道是怎么回事。我已经画出了图像,想知道是否包括已经脱离边界的形状的部分,但它看起来不像那样。我无法解决这个问题,直到我知道为什么它的表现如此。我会非常感谢任何见解或猜测。谢谢

编辑:我知道我应该在这里使用选择器,但我只是现在就测试这个。实际完成后,图像不会呈现哑光黑色。

回答

0

首先,我要感谢大家,试图帮助。原来,YoungCoconut走上了正轨。当我将这些项目的尺寸设置得更适合反映它们缩放到图像形状的大小就像我实际看到的一样。所以看起来,即使已经被切断的部分物体仍然被保存。渲染根本不在预览窗格中使用图像,而是在缩放时一次构建一个对象。我使用Krita来构建对象并将它们加载到项目中。

0

我认为这是因为你正在使用像200dp这样的大尺寸。尝试将所有内容缩小到您想要的实际按钮的大小。

如果不行看看你是否可以在按钮上的android:scaleType属性设置为类似android:scaleType="fitXY"

+0

android:scaleType不是我的按钮的选项。有scaleX和scaleY –

+0

尝试设置都为0.5或0.25 – YoungCoconutCode

+0

好吧原来scaleType是ImageViews的一个属性而不是按钮。我尝试切换到ImageView并使用scaleType进行播放。我将图像尺寸减少了90%。我切换回一个按钮,并与scaleX和scaleY混淆。没有工作。尽管如此,感谢您的尝试。它的赞赏。 –