2011-10-21 83 views
1

我想要在Android中定义一个漂亮的圆角正方形,但我只能得到一个不错的圆角矩形。Android可绘制形状:将矩形变为方形

我在/ RES /绘制看起来这样的XML:除了

<size android:width="3dp" android:height="3dp" /> 

这我一直希望做的东西方,但没有这样的运气

<?xml version="1.0" encoding="utf-8"?> 
<selector 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res/uk.co.alexlydiate.sequencer"> 

<item android:state_pressed="true" 
     app:state_playing = "true" > 
    <shape> 
     <stroke 
      android:width="2dp" 
      android:color="@color/red" /> 
     <corners 
      android:radius="3dp" /> 
     <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp" /> 
     <solid 
      android:color="@color/blue" /> 
     <size 
      android:width="3dp" 
      android:height="3dp" /> 
    </shape>   
</item> 
</selector> 

而且一切工作正常。

我的布局是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/grid8x8" 
    android:gravity="center" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

<uk.co.alexlydiate.sequencer.Key android:background="@drawable/key"   
    android:id="@+id/keyA1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" android:layout_margin="2px" 
/> 
<uk.co.alexlydiate.sequencer.Key android:background="@drawable/key"   
    android:id="@+id/keyA2" 
    android:layout_below="@+id/keyA1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" android:layout_margin="2px" 
/> 
</RelativeLayout> 

任何人有什么好主意?谢谢!

回答

0

AFAIK:shapes根据View的布局自行伸展。 相反,您可以定义正方形View并设置shape背景。

OR

使用图像作为背景