小编Yul*_*kov的帖子

裁剪动画图像

Android动画API有很多麻烦.

我需要在屏幕(600px*1024px)上从左下角到顶部动画图像(400px*600px).此外,在动画开始时,大部分图像应位于屏幕之外.

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/common_background">

<ImageView android:id="@+id/hand"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:scaleType="matrix"
           android:src="@drawable/howto_throw_hand" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

活动的逻辑:

public class MyActivity extends Activity
{
    ImageView hand;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        hand = (ImageView)findViewById(R.id.hand);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {

        //initial positioning
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                new ViewGroup.MarginLayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT
                )
        );
        layoutParams.setMargins(400, 600, 0, 0);
        hand.setLayoutParams(layoutParams);

        //making animation
        TranslateAnimation animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0, Animation.ABSOLUTE, -100,
            Animation.RELATIVE_TO_SELF, 0, Animation.ABSOLUTE, -1000
        ); …
Run Code Online (Sandbox Code Playgroud)

android android-ui android-animation android-layout

6
推荐指数
1
解决办法
1714
查看次数