1

首先,对不起我的英语,我是越南人,我的英语很差,所以请不要生气,好吧!

大家好,我必须使用布局动画(左推和右推)创建一个应用程序,这是我的代码:

ArrayList<LinearLayout>linear=new ArrayList<LinearLayout>();
Animation animLeft,animRight;



     for(int i=0;i<10;i++)
            {
                LinearLayout llayout=new LinearLayout(getApplicationContext());
                LinearLayout.LayoutParams lp=new       LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
                lp.setMargins(0, 0, 0, 0);
                llayout.setLayoutParams(lp);
                llayout.setId(i);
                if(i%2==0)
                {
                    llayout.setAnimation(animLeft);
                    Log.d("SetAnimation,Left","i:"+i);
                    llayout.startLayoutAnimation();
                }
                else
                {
                    llayout.setAnimation(animRight);
                    Log.d("SetAnimation,Right","i:"+i);
                    llayout.startLayoutAnimation();
                }
                linear.add(llayout);
            }

//动画代码:

+左推

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
     </set>

+推右

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="300"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
     </set>

    public void CreateGame(int round)
{

    ///////////Load all method//////////////
    tvarray=TaoTextView(round);
    addTexttoLayoutbyRandom(round, tvarray);

    for(int i=0;i<round;i++)
    {
        Linearcenter.addView(linear.get(i));
        //linear.get(i).startLayoutAnimation();

    }
    ////////////////////////////////////////
    Linearcenter.startLayoutAnimation();
    iResult=RandomRound(round);
    iRound=round;
    //Linearcenter.startLayoutAnimation();
}

我在 CreateGame 中设置onCreate(),请忽略一些无关的参数(如 round、iRound、iResult ..),当应用程序启动时,我只看到 1 个子布局效果,这是第一个布局,有id = 0 什么问题?请告诉我为什么?

4

0 回答 0