android中横向放按钮,如何动画Android中的按钮以横向扩展?

4 个答案:

答案 0 :(得分:0)

首先定义2个Animation和Button对象,然后为Button创建一个On Click侦听器,并在其中编写以下代码:

//here i define :Button btnoff

//Animation animation1

//set on click listener in oncreate

btnOff.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

animation1 = new ScaleAnimation(0,2,1,1,

Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

animation1.setDuration(1200);

btnOff.startAnimation(animation1);}

});

您可以在此link中了解更多信息。

答案 1 :(得分:0)

我认为您可以将this库用于Button 2动画。

为了在点击另一个按钮时发生,只需从View.performClick() onClick()方法调用Button 2 Button 1。

答案 2 :(得分:0)

平滑的动画效果,可以使用ObjectAnimtor。

答案 3 :(得分:0)

// scale down button2 at the start of an activity

btn2.setScaleX(0.1f);

// on the click of button 1 let the button2 scale

btn1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

btn2.animate()

.scaleX(4.0f)

.setDuration(1000)

.setInterpolator(new OvershootInterpolator(2.0f)) //Will give bounce effect to the scaling

.start();

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 横向扫描的动画可以通过使用 ViewPropertyAnimator 和 ObjectAnimator 来实现。 首先,在 XML 布局文件创建一个 ImageView,并设置其宽度为 0dp,高度为 match_parent。然后,创建一个横向的渐变色 Drawable,并将其设置为 ImageView 的背景。最后,使用 ViewPropertyAnimator 来设置 ImageView 的宽度变化,实现横向扫描的动画效果。 具体实现步骤如下: 1. 在 XML 布局文件添加 ImageView 和横向渐变色 Drawable: ``` <ImageView android:id="@+id/scan_line" android:layout_width="0dp" android:layout_height="match_parent" android:background="@drawable/scan_gradient" /> ``` 2. 创建一个横向渐变色 Drawable,命名为 scan_gradient.xml: ``` <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFFFFFF" android:endColor="#00FFFFFF" android:type="linear" android:angle="0"/> </shape> ``` 3. 使用 ViewPropertyAnimator 来设置 ImageView 的宽度变化: ``` // 获取 ImageView ImageView scanLine = findViewById(R.id.scan_line); // 获取屏幕宽度 int screenWidth = getResources().getDisplayMetrics().widthPixels; // 设置 ViewPropertyAnimator scanLine.animate() .translationX(screenWidth) // 横向移动到屏幕右侧 .setDuration(3000) // 动画时长为 3 秒 .setInterpolator(new LinearInterpolator()) // 设置动画插值器 .withEndAction(new Runnable() { @Override public void run() { // 动画结束后,重新设置 ImageView 的宽度为 0 scanLine.setTranslationX(0); scanLine.animate().setStartDelay(1000).start(); } }) .start(); ``` 上述代码,使用 setDuration 方法设置动画时长为 3 秒,使用 setInterpolator 方法设置动画插值器为 LinearInterpolator,使得动画的速度保持匀速不变。使用 withEndAction 方法设置动画结束后的回调,重新设置 ImageView 的宽度为 0,并使用 setStartDelay 方法设置动画延迟 1 秒后再次启动,实现无限循环横向扫描的动画效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值