2016-03-15 79 views
0

我正在寻找在android(xml)中创建这种自定义按钮的正确方法。 enter image description here如何在android xml中创建自定义按钮

我知道我可以将此图像设置为按钮的背景,但我正在寻找一种方法来使用xml重新创建它,以使其对各种屏幕尺寸的响应。

+0

我想你会在这里有解决方案[这里](http://stackoverflow.com/questions/23483060/android-responsive-image-button-layout) –

+0

这不是我正在寻找什么,我是什么毫无疑问,这是用xml编写的精确设计。无论如何感谢您的回复 –

回答

2

您可以使用层列表来实现使用XML的设计。 下面是一个例子:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:left="60dp"> 
    <shape> 
     <size 
      android:width="200dp" 
      android:height="120dp"/> 
     <gradient 
      android:startColor="#474946" 
      android:endColor="#181818" 
      android:angle="270"/> 
     <corners android:topLeftRadius="2dp" android:topRightRadius="2dp" 
      android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp"/> 
    </shape> 
</item> 
<item android:right="140dp"> 
    <shape android:shape="oval"> 
     <size 
      android:width="120dp" 
      android:height="120dp"/> 
     <solid android:color="#000000"/> 
    </shape> 
</item> 

您也可以使用9补丁这一点。

+0

感谢您的代码我会试一试。但我只是好奇,如果一个9补丁图像拉伸时会以正确的方式表现出来? –

+0

非常感谢你匹配!!!!!它的作品像一个魅力! –