gpt4 book ai didi

android - 如何在点击按钮后以编程方式放大按钮或 View

转载 作者:太空宇宙 更新时间:2023-11-03 13:21:00 25 4
gpt4 key购买 nike

我的应用程序中有一些按钮,我想在它们被点击时放大

为此我创建了一个选择器

selector_sms_button.xml

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

<item android:drawable="@drawable/ic_sms_big" android:state_pressed="true"></item>
<item android:drawable="@drawable/ic_sms" android:state_pressed="false"></item>

</selector>

并如下声明我的按钮

  <Button
android:id="@+id/sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_sms_button" />

问题是 - 按钮根本不会在点击时增长
ic_sms_big 的大小为 300x300dp,ic_sms 的大小为 72x72dp

如果绝对不需要,我不想为他们创建动画文件。问题是单击时按钮应该至少增长到其大小的 3 倍,但事实并非如此。

我该怎么做才能修复它?

编辑:我的请求“我不想创建动画文件”并不意味着我不想为其创建 XML 文件,而是我根本不想在代码中为其创建引用。我有 6 个按钮可以做到这一点

最佳答案

如果你不想添加一个文件,你可以通过编程来完成

Animation anim = new ScaleAnimation(
1f, 1f, // Start and end values for the X axis scaling
startScale, endScale, // Start and end values for the Y axis scaling
Animation.RELATIVE_TO_SELF, 0f, // Pivot point of X scaling
Animation.RELATIVE_TO_SELF, 1f); // Pivot point of Y scaling
anim.setFillAfter(true); // Needed to keep the result of the animation
v.startAnimation(anim);

关于android - 如何在点击按钮后以编程方式放大按钮或 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27617401/

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