我的图标有这样的布局:
<LinearLayout
android:id="@+id/icon_layout"
android:layout_width="36dp"
android:layout_height="36dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/ic_globe"
/>
</LinearLayout>
我想这样做,如果点击布局:
24dp
缩放到32dp
然后再回到24dp
)我该怎么做?
答案 0 :(得分:0)
听起来你想将LinearLayout的背景设置为发出&#34; red&#34;的StateListDrawable。在压制状态下可绘制。对于动画,您必须在XML中定义animation,然后使用以下命令运行该动画:
ImageView iconLayout = (ImageView) findViewById(R.id.icon_layout);
Animation expandAnimation = AnimationUtils.loadAnimation(this, R.anim.icon_expand);
iconLayout.startAnimation(expandAnimation);
答案 1 :(得分:0)
试试这个:
ImageView imageView = (ImageView) findViewById(R.id.icon);
imageView.animate().scaleX(newScaleX).scaleY(newScaleY).alpha(1).setDuration(300).start();
答案 2 :(得分:0)
尝试淡出
private Animation animation;
animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
//Use this animation where ever you want to use
icon.startAnimation(animation);