2011-10-22 53 views
0

如何在Android XML中创建像iPhone背部按钮这样的尖锐按钮?如何在android上创建尖锐的按钮?

enter image description here

我要创建使用这样

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

    <item android:state_pressed="true" > 
     <shape> 
      <gradient 
       android:startColor="#f8bb49" 
       android:endColor="#f7941d" 
       android:angle="270" /> 
      <stroke 
       android:width="1dp" 
       android:color="#8c8382" /> 
      <corners..... 

回答

0

看起来你有一张你可以使用的图像。阅读9个补丁的文档以设置边距和可调整大小的区域。

http://developer.android.com/guide/developing/tools/draw9patch.html

+0

我已更新问题...请检查 – aNi

+0

您的形状有5个c orners。内置的int形状是矩形,椭圆形,线形和环形。您仍然可以使用您的选择器,只需生成不同版本的9修补程序可绘制图形资源。 – Krylez

0

那样创建图像和使用,而不是按钮 的ImageButton,并使用该属性的ImageButton

android:background="@drawable/createdimage" 
+0

我已更新问题...请检查 – aNi

1

路径和PathShape可以建立任何你想要的。通过将一对夫妇分层并使用渐变填充,您可以创建3D效果(凹陷)效果。

但是,如果您希望能够使用XML定义,您将需要一个可用于创建可绘制引用的类。对不起,我还没有制定出确切的代码,但这是我打算做的事情(这是我如何找到你的问题)。

0

我使用XML文件,这样做是为了下面的后退按钮

https://drive.google.com/file/d/0B1cySRpqElgyTkptOFpQa3NsdDQ

left_arrow.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item > 
     <rotate 
      android:fromDegrees="-45" 
      android:toDegrees="-45" 
      android:pivotX="89%" 
      android:pivotY="-22%" > 
      <shape 
       android:shape="rectangle" > 
       <stroke android:color="@color/calendarOrange" android:width="3dp"/> 
       <solid 
        android:color="@color/drakBlue" /> 
      </shape> 
     </rotate> 
    </item> 
</layer-list> 

button_body.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:left="-4dp"> 
     <shape android:shape="rectangle" > 
       <stroke android:color="@color/calendarOrange" android:width="3dp"/> 
       <solid 
        android:color="@color/drakBlue" /> 
     </shape> 
    </item> 
</layer-list> 

让他们一起

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="1.0" 
    > 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/left_arrow" 
     android:layout_weight="0.7" 
     > 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/button_body" 
     android:layout_weight="0.3" 
    > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:textColor="@color/white" 
      android:text="Back" 
      android:gravity="center" 
      android:textStyle="bold" 
      android:textSize="22dp" 
     /> 
    </RelativeLayout> 
</LinearLayout> 

PS:您可能需要改变安卓pivotX安卓pivotY参数取决于你conteiner布局