背景颜色停止我的动画

时间:2014-07-25 12:47:30

标签: android animation

我有一个按钮的问题,如果添加他的背景我的动画停止工作。

这是xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@drawable/coinsbackground" >

    <LinearLayout
        android:id="@+id/instructiuni"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0" >

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical" >

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:src="@drawable/instructiuneinceput" />

                <TextView
                    android:id="@+id/instructiuniInceputHtml"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text=""
                    android:background="#8CFAFAFA" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:src="@drawable/terminareinceput" />

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:src="@drawable/intructiuni" />

                <TextView
                    android:id="@+id/instructiuniHtml"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text=""
                    android:background="#8CFAFAFA"  />

                <Button
                    android:id="@+id/back_instructiuni"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Back >>"
                    android:background="#5B52D7" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/menuButton"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center"
        >

        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:layout_weight="1" >
            </LinearLayout>

        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:layout_weight="18" >

        <Button
            android:id="@+id/playgame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Play"
            android:textStyle="bold" />

        <Button
            android:id="@+id/instructions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Instructions"
            android:textStyle="bold" />

        <Button
            android:id="@+id/settings"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Settings"
            android:textStyle="bold"
            android:background="#5B52D7" />

        </LinearLayout>


        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:layout_weight="1" >
            </LinearLayout>
    </LinearLayout>

</LinearLayout>

我的动画类:

    public class FlipWidthAnimation extends Animation {


    private int startWidth;
    private int deltaWidth; // distance between start and end height
    private View view;

    /**
     * constructor, do not forget to use the setParams(int, int) method before
     * starting the animation
     * @param v
     */
    public FlipWidthAnimation(View v) {
        this.view = v;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {

        view.getLayoutParams().width = (int) (startWidth + deltaWidth * interpolatedTime);
        view.requestLayout();
    }

    /**
     * set the starting and ending height for the resize animation
     * starting height is usually the views current height, the end height is the height
     * we want to reach after the animation is completed
     * @param start height in pixels
     * @param end height in pixels
     */
    public void setParams(int start, int end) {

        this.startWidth = start;
        deltaWidth = end - startWidth;
    }

    /**
     * set the duration for the hideshowanimation
     */
    @Override
    public void setDuration(long durationMillis) {
        super.setDuration(durationMillis);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
}

这里的事件:

if(v.getId() == R.id.instructions){
        LinearLayout instructiuni = (LinearLayout)findViewById(R.id.instructiuni);

        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) instructiuni.getLayoutParams();
        FlipWidthAnimation a = new FlipWidthAnimation(instructiuni);
        a.setDuration(1000);

        a.setParams(lp.width, getWindowManager().getDefaultDisplay().getWidth());
        instructiuni.startAnimation(a);
    }

他参加活动不是问题,我发现我看不到任何错误,但是动画没有开始,但是例如如果点击设置动画开始,如果在按下设置之前是预设指令。真的没有任何想法。

0 个答案:

没有答案