【问题标题】:Android drawable shape : make Rectangle into a SquareAndroid可绘制形状:将矩形变成正方形
【发布时间】:2011-10-21 13:22:16
【问题描述】:

我试图在 Android 中定义一个漂亮的圆角方形,但我只能得到一个漂亮的圆角矩形。

我在 /res/drawable 中的 xml 如下所示:

<?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>

一切正常,除了

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

我希望这能让事情变得平淡无奇,但没有这样的运气。

我的布局是这样的:

 <?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>

有人有什么好主意吗?谢谢!

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

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

    使用图片作为背景

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 2016-03-23
      • 1970-01-01
      • 2016-09-21
      • 2020-04-29
      • 1970-01-01
      相关资源
      最近更新 更多