Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Gmail listview翻转动画_Android_Android Animation_Android 5.0 Lollipop - Fatal编程技术网

Android Gmail listview翻转动画

Android Gmail listview翻转动画,android,android-animation,android-5.0-lollipop,Android,Android Animation,Android 5.0 Lollipop,我试图创建一个动画,就像我们在Gmail的listview小部件中看到的那样。当我们选择行时,按下左边的圆圈,它会翻转成选中标记 我计划做的是创建一个动画集,带有两个缩放动画。出于某种奇怪的原因,它不起作用 我正在使用一个单一的图像暂时和应用翻转到那个。这是我的anim.xml: <?xml version="1.0" encoding="utf-8"?> <set> <scale android:duration="2000"

我试图创建一个动画,就像我们在Gmail的listview小部件中看到的那样。当我们选择行时,按下左边的圆圈,它会翻转成选中标记

我计划做的是创建一个动画集,带有两个缩放动画。出于某种奇怪的原因,它不起作用

我正在使用一个单一的图像暂时和应用翻转到那个。这是我的anim.xml:

<?xml version="1.0" encoding="utf-8"?>
<set>
    <scale
        android:duration="2000"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="0.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        >
    </scale>
    <scale
        android:startOffset="2000"
        android:duration="2000"
        android:fromXScale="0.0"
        android:fromYScale="1.0"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        >
    </scale>
</set>

我做错了什么?

我无法识别该程序中的任何特定缺陷,不知何故它对我不起作用,如果您感兴趣,您可以查看我的其他定制,希望它能帮助您。 Javaclass

import android.animation.AnimatorSet;
import android.animation.AnimatorInflater;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
    AnimatorSet set;
    Button horizontal,vertical;
     ImageView imgView;
     Animation in;
    Boolean check=false;
    protected void onCreate(Bundle savedInstanceState) {
        //TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        horizontal=(Button)findViewById(R.id.button);
        vertical=(Button)findViewById(R.id.button2);
         in = new AlphaAnimation(0.0f, 1.0f);
        in.setDuration(300);
        horizontal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                imgView  = (ImageView) findViewById(R.id.imageview);
                set = (AnimatorSet) AnimatorInflater.loadAnimator(MainActivity.this, R.animator.animfliphorizontal);
                set.setTarget(imgView);
                set.start();
                anim();
            }


        });
        vertical.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              imgView=(ImageView)findViewById(R.id.imageview);
                set = (AnimatorSet) AnimatorInflater.loadAnimator(MainActivity.this, R.animator.animflipvertical);
                set.setTarget(imgView);
                set.start();
                anim();
            }
        });
    }

    private void anim() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
if(check==false)
{
    check=true;
    imgView.setImageResource(R.drawable.background2);
}
                else
{
    check=false;
    imgView.setImageResource(R.drawable.background);
}
                imgView.setAnimation(in);

            }
        }, 500);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
}
下面你可以看到一个xml文件和两个不同的水平和垂直对象动画,请查看

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    >
    <ImageView
        android:id="@+id/imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/background"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="HORIZONTAL"
        android:id="@+id/button"
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="VERTICAL"
        android:id="@+id/button2"
        android:layout_centerVertical="true"
        android:layout_toEndOf="@+id/imageview" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="FLIP MODE"
        android:id="@+id/textView"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true" />
</RelativeLayout> 

以及它们的2个动画文件夹

<?xml version="1.0" encoding="utf-8"?>
<!--animfliphorizontal-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
        android:duration="1000"
        android:propertyName="rotationX"
        android:valueFrom="180"
        android:valueTo="0" >
    </objectAnimator>
</set>
<?xml version="1.0" encoding="utf-8"?>
<!--animflipvertical-->
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially" >
    <objectAnimator
        android:duration="1000"
        android:propertyName="rotationY"
        android:valueFrom="0"
        android:valueTo="180" >
    </objectAnimator>
</set>

你真幸运!!因为我刚刚开发了一个新的库,其中包括基本翻转动画和扩展
ViewFlipper
。我指的是一个完全可定制的库,在这里你可以将任何类型的视图和布局与你想要的任何类型的动画和形状(以及更多)交换,包括你搜索的Gmail图像翻转


请看一看。

这是确切的答案:

1) 在动画文件夹中定义两个动画xml文件:

scale_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:fromXScale="0.0"
    android:toXScale="1.0"
    android:fromYScale="1.0"
    android:toYScale="1.0"
    android:pivotX="50%"
    android:fillAfter="false"
    android:duration="150" />
然后:

animation.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //your code for change the layout image or ...

                Animation animation2 = AnimationUtils.loadAnimation(YourActivity.this, R.anim.scale_in);
                layoutWithCircleDrawable.startAnimation(animation2);
            }
        });
<?xml version="1.0" encoding="utf-8"?>
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:fromXScale="1.0"
    android:toXScale="0.0"
    android:fromYScale="1.0"
    android:toYScale="1.0"
    android:pivotX="50%"
    android:fillAfter="false"
    android:duration="150" />
Animation animation = AnimationUtils.loadAnimation(YourActivity.this, R.anim.scale_out);
layoutWithCircleDrawable.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //your code for change the layout image or ...

                Animation animation2 = AnimationUtils.loadAnimation(YourActivity.this, R.anim.scale_in);
                layoutWithCircleDrawable.startAnimation(animation2);
            }
        });