将渐变背景设置为按钮会自动调整其大小

时间:2014-12-15 05:09:50

标签: android xml

我正在尝试将渐变xml文件设置为按钮的背景。但是当我将可绘制的xml文件添加为背景时,按钮的大小会发生变化。按钮位于edittext右侧,按钮大小变得比编辑文本更大。

代码:

按钮:

<Button
            android:id="@+id/btndob"
            android:layout_width="127dp"
            android:textColor="#FFFFFF"
            android:background="@drawable/button_clicked_selector"
            android:layout_height="fill_parent"
            android:text="SELECT DATE" />

button_clicked_selector.xml

<?xml version="1.0" encoding="utf-8" ?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@drawable/button_gradient" /> 
<item android:state_pressed="true" android:drawable="@drawable/button_clicked_gradient" /> 
</selector>

button_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
    <!--  Gradient Bg for listrow -->
   <gradient
      android:startColor="#00aff0"
      android:endColor="#0081b0"
      android:angle="270" />
</shape>

button_clicked_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
    <!--  Gradient Bg for listrow -->
   <gradient
      android:startColor="#00aff0"
      android:endColor="#00aff0"
      android:angle="270" />
</shape>

0 个答案:

没有答案