我该如何构建这样的按钮?

时间:2012-03-02 09:55:06

标签: android user-interface

我需要为我的Android应用实现这样的按钮。如果不使用完整图像作为按钮,这样做会很棒 我使用<shape><gradient>完成了几乎相同的按钮。我唯一需要的是添加底部的蓝色按钮阴影并包含图像。

Button

有可能吗?

提前致谢。

3 个答案:

答案 0 :(得分:1)

使按钮的android:background属性指向所需的图像。使用文本和小人物图标创建图像。在按钮内同时放置文本和图像是不可能的。

对于蓝色阴影,您可以将其包含在图像中,也可以使用渐变属性获得与您在问题中所述相同的结果。

答案 1 :(得分:1)

您可以通过在分层Drawable中组合Shape Drawable来实现此目的。为此,您将拥有3个xml文件,如下所示:

  • button.xml(我猜你已经拥有的那个)

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    
        <corners android:radius="16dp" />
    
        <gradient
            android:angle="270"
            android:centerColor="#FFFFFF"
            android:endColor="#CAEBF8"
            android:startColor="#FFFFFF"
            android:type="linear" />
    
        <padding
            android:bottom="8dp"
            android:left="8dp"
            android:right="8dp"
            android:top="8dp" />
    
        <stroke
            android:width="2dp"
            android:color="#FFFFFF" />
    
    </shape>
    
  • button_bg.xml(添加按钮下方的蓝色边框)

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    
        <corners android:radius="16dp" />
    
        <solid android:color="#6FC8F1" />
    
    </shape>
    
  • layered_button.xml(结合以前的xml,以及drawable用作按钮的背景)

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item android:drawable="@drawable/button_bg"/>
        <item
            android:bottom="2dp"
            android:drawable="@drawable/button"/>
    
    </layer-list>
    

您可以在Drawables Documentation

中找到有关图层列表的更多信息

答案 2 :(得分:-1)

对于图像,您应该使用

android:drawableRight

至于阴影,我不确定这是如何实现的。

相关问题