Android中的滑动动画

3

我希望从左向右滑动(在下面的代码中相反地从右向左)。目前,我的任务在点击按钮时可以正常运行。

以下是源代码:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    Button btnopen = (Button)findViewById(R.id.btnWindowAnimation);
     
    btnopen.setOnClickListener(new View.OnClickListener() {
     
    @Override
    public void onClick(View v) {
     
    Intent i = new Intent(MainActivity.this, SecondActivity.class);
     
    Bundle bundle =ActivityOptions.makeCustomAnimation(getApplicationContext(), `              `R.anim.animation,R.anim.animation2).toBundle();
    startActivity(i, bundle);
     
    }
    });
    
}

这里是动画1:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500"/>

这里是动画2:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-50%p"
android:duration="500"/>

请尝试此链接http://www.androidhive.info/2013/06/android-working-with-xml-animations/ @Banku - Pankaj Kharche
我已经尝试了上面给出的链接,但我不需要那个。@PSK - Kumar Bankesh
2个回答

3

这是用于左到右动画的代码:

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
 <translate android:fromXDelta="-100%" android:toXDelta="0%"
         android:fromYDelta="0%" android:toYDelta="0%"
         android:duration="700"/>
</set>

这是用于从右到左的动画效果:

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
<translate
 android:fromXDelta="0%" android:toXDelta="100%"
 android:fromYDelta="0%" android:toYDelta="0%"
 android:duration="700" />
</set>

Check this link.


2

这里是第一个答案:

 <translate 
     android:fromXDelta="-100%" 
     android:toXDelta="0%"
     android:duration="500"/>
</set>

这里是第二个XML:

<translate
 android:fromXDelta="0%"
  android:toXDelta="100%"
  android:duration="500" />
</set>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接