为什么位移动画实现不了啊!本人要疯了

Android 码拜 8年前 (2016-05-30) 880次浏览
太奇怪了!本人就放了一个按钮一个图片 点击按钮图片向下平移,可是为什么本人点了按钮一点反应没有,然后本人把屏幕关了再开一次,发现动画居然在执行了!这是个什么原因啊 百思不得其解啊!
代码如下:
public void click(View v) {
TranslateAnimation ta = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT,
0, Animation.RELATIVE_TO_PARENT, 0,
Animation.RELATIVE_TO_PARENT, 0.2f);
ta.setDuration(2000);
ta.setFillAfter(true);
iv_p.setAnimation(ta);
}
布局就这样:
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
tools:context=”com.example.scollertextview.MainActivity” >
<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:onClick=”click”
android:text=”位移”
/>
<ImageView
android:id=”@+id/iv_p”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/ic_launcher”
/>
</LinearLayout>
解决方案

40

startAnimation

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明为什么位移动画实现不了啊!本人要疯了
喜欢 (0)
[1034331897@qq.com]
分享 (0)