2017-01-09 82 views

回答

0

您可以创建一个transition文件。例如:

<?xml version="1.0" encoding="utf-8"?> 
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" 
    android:transitionOrdering="together" 
    android:duration="250"> 
    <slide android:slideEdge="right"> 
     <targets> 
      <target android:targetId="@id/toolbar" /> 
     </targets> 
    </slide> 
</transitionSet> 

然后在代码中你开始你的活动:

Intent intent = new Intent(this, YourActivityHere.class); 
ActivityOptionsCompat activityOptions = 
     ActivityOptionsCompat.makeSceneTransitionAnimation(this, 
     new Pair<View, String>(viewHolder.mIconView, getString(R.string.detail_icon_transition_name))); 
ActivityCompat.startActivity(this, intent, activityOptions.toBundle()); 
0

使用这个库,方便TextView的动画包括左到右 链接 - >Here

enter image description here enter image description here enter image description here

或以编程方式从X ---到------> X1的简单动画(您可以通过更改负值/正值来恢复),

创建anim文件夹res(新建>目录)> anim

添加资源XML

move_it.xml

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:fillAfter="true"> 

    <translate 
     android:fromXDelta="-3%p" 
     android:toXDelta="30%p" 
     android:duration="1200" /> 
</set> 

,并在你的代码

textView = (TextView) findViewById(R.id.text_one); 
textView.startAnimation(AnimationUtils.loadAnimation(YourActivityName.this, R.anim.move_it)); 
+0

它说 - 无法找到以下类com.hanks.htextview.Htextview –

+0

@ K.A. Siddiqui你知道如何使用它吗? 1.在您的gradle中添加依赖项并同步它。2.然后您可以使用它们的自定义XML ..您可以提供您想要的动画类型!阅读**使用**部分,展示如何使用它,它的作用就像魅力,如果你需要一个正常的,你可以使用我的代码示例 –

0

TextSwitcher如何,每当文本发生变化,然后发生动画。

<TextSwitcher 
     android:id="@+id/txtSwitcher" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

然后在你的代码:

TextSwitcher switcher = (TextSwitcher)findViewById(txtSwitcher); 
    switcher.setFactory(new ViewFactory() { 
     @Override 
     public View makeView() { 
      TextView t = new TextView(ActivityClass.this); 
      //do other stuff the suit your needs 
      return t; 
     } 
    }); 

    Animation in = AnimationUtils.loadAnimation(this, 
      android.R.anim.slide_in_left); 
    Animation out = AnimationUtils.loadAnimation(this, 
      android.R.anim.slide_out_right); 

    switcher.setInAnimation(in); 
    switcher.setOutAnimation(out); 

如果你switcher.setText( “新文本”),则动画会发生。

相关问题