1

我在片段中有逐帧动画,

但我需要将动画放在不同的地方,

到目前为止,我可以制作一个动画 在此处输入图像描述 [头上的那个]

那么如何将其他动画放置在特定的 X 和 Y 位置,并使它们具有动画效果?

这里我使用的代码:

.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="#FF0000">


<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">

       <ImageView 
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:src="@drawable/home_bgnd" android:scaleType="fitXY" />




    <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <ImageView     android:id="@+id/imgTesto"
       android:contentDescription="@string/imageFrag1"
       android:layout_x="265dp"
       android:layout_y="23dp"
            android:layout_width="41dp" 
            android:layout_height="41dp"
            android:src="@drawable/c_0"
    />

   <ImageView     android:id="@+id/imgTesto1"
       android:contentDescription="@string/imageFrag1"
       android:layout_x="265dp"
       android:layout_y="100dp"
            android:layout_width="41dp" 
            android:layout_height="41dp"
            android:src="@drawable/c_0"
    />

    </AbsoluteLayout>


</RelativeLayout>


<Button
       android:id="@+id/button1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="TesteoB" />


</LinearLayout>

和.java

public class HomeTab extends Fragment {
    /* (non-Javadoc)
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */

    AnimationDrawable animation;

    AnimationDrawable animation1;

    //ImageButton yourButton = new ImageButton(this);


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) {
            // We have different layouts, and in one of them this
            // fragment's containing frame doesn't exist.  The fragment
            // may still be created from its saved state, but there is
            // no reason to try to create its view hierarchy because it
            // won't be displayed.  Note this is not needed -- we could
            // just run the code below, where we would create and return
            // the view hierarchy; it would just never be used.
            return null;
        }


        //animation 0
        animation = new AnimationDrawable();
        animation.addFrame(getResources().getDrawable(R.drawable.c_0), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c1), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c2), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c3), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c4), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c5), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c6), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c7), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c8), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c9), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c10), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c9), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c8), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c7), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c6), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c5), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c4), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c3), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c2), 100);
        animation.addFrame(getResources().getDrawable(R.drawable.c1), 100);

        animation.setOneShot(false);


        //animation 1
        animation1 = new AnimationDrawable();
        animation1.addFrame(getResources().getDrawable(R.drawable.c_0), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c1), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c2), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c3), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c4), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c5), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c6), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c7), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c8), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c9), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c10), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c9), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c8), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c7), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c6), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c5), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c4), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c3), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c2), 100);
        animation1.addFrame(getResources().getDrawable(R.drawable.c1), 100);

        animation1.setOneShot(false);



        View V = inflater.inflate(R.layout.tab_home_layout, container, false);


        ImageView imageView = (ImageView)V.findViewById(R.id.imgTesto); //mestrua imagen ok, en el fragmentus

        //animation 0
        imageView.setBackgroundDrawable(animation);

        imageView.post(new Starter());

        //animation 1
        /*
        ImageView imageView1 = (ImageView)V.findViewById(R.id.imgTesto1); //mestrua imagen ok, en el fragmentus

           imageView1.setBackgroundDrawable(animation);

            imageView1.post(new Starter());
        */
        return V;


    }


     class Starter implements Runnable {

        public void run() {
            animation.start();        
        }

    }





}

那么如何避免制作动画0、动画1、动画N

一样,只是在不同的位置?

还请注意我使用已弃用的AbsoluteLayout

谢谢!

4

0 回答 0