当我按下这些左右箭头按钮
时,我想在按钮上看到这些类型的效果。默认情况下,Iphone/IOS
中也会发生同样的情况。
我可以制作这种效果吗?
在这里我提到了我想要的图片。
这里我使用了这个xml文件,但没有成功。
button_pressed.xml
<?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:angle="180" android:centerColor="#657377" android:endColor="#AFFFFFFF" android:startColor="#FFFFFFFF" android:type="linear"/>
<corners android:radius="10dp" />
</shape></item>
</selector>
编辑
我使用了 android:background="@drawable/button_pressed.xml"
行,但我没有得到我想要的确切内容。
尝试过:
我按照 Piyush 的回答使用了这个 xml 文件,但没有成功,但得到了这个效果。
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/transparent" />
</shape>
</item>
<item>
<shape
android:innerRadiusRatio="4"
android:shape="ring"
android:thicknessRatio="9"
android:useLevel="false" >
<gradient
android:endColor="#00000000"
android:gradientRadius="250"
android:startColor="#ffffffff"
android:type="radial" />
</shape>
</item>
</layer-list>
我同意顶部和底部部分的切割,因为我的这个按钮的布局空间有限。我们稍后会想到,但为什么它没有像阴影和阿尔法那样生效以及我提到的所有这些?
输出:
如果有人对此有任何想法,请帮助我。
提前致谢。
最佳答案
形状必须以放射状绘制,并从白色向外渐变为黑色。
试试这个:
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#ffffffff"
android:endColor="#00000000"
android:gradientRadius="100"
android:type="radial"/>
</shape>
此外,您不能直接将其设置为按钮的背景。您必须创建一个选择器可绘制文件,在其中根据按钮的状态指定不同的背景。在这种情况下,您需要仅在按下按钮时设置背景。选择器看起来像这样:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/button_pressed"/>
<item android:state_selected="true" android:drawable="@drawable/button_pressed"/>
<item android:state_focussed="true" android:drawable="@drawable/button_pressed"/>
<item android:drawable="@android:color/transparent" />
</selector>
PS:不建议在设计Android应用程序时复制iOS设计。 Android设计指南请引用:http://developer.android.com/design/building-blocks/buttons.html
关于安卓 : Image button or button Highlighted with Effect when Pressed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16514221/