gpt4 book ai didi

安卓 : Image button or button Highlighted with Effect when Pressed

转载 作者:行者123 更新时间:2023-11-29 00:29:49 24 4
gpt4 key购买 nike

此时,当我按下这些 左右箭头按钮 时,我想在按钮上看到这些类型的效果。默认情况下,Iphone/IOS 中也会发生同样的事情。

我可以制作这种效果吗?

这里我提到了我想要的图片。

enter image description here

我在这里使用了这个 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>

我同意切割顶部和底部部分,因为我在布局中为这个按钮设置的空间有限。我们稍后会考虑,但为什么它不像阴影和 alpha 那样生效,就像我提到的那样?

输出:enter image description here

如果有人对此有想法,请帮助我。

提前致谢。

最佳答案

形状必须呈放射状绘制,从白色向外逐渐变黑。

试试这个:

<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设计。安卓设计指南请引用: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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com