如何创建带动画的 TextSwitcher
How to create a TextSwitcher with Animation
我想创建一个带有动画闪烁的 TextSwitcher。
当它消失时,应该更改文本。
这是我的眨眼
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="2000"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
包含 TextSwitcher 的我的片段
private TextSwitcher Test ;
public HomeFragment() {
// Required empty public constructor
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
Test = (TextSwitcher)rootView.findViewById(R.id.TEST) ;
Animation LeftSideAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.blink);
Animation in = AnimationUtils.loadAnimation(getActivity(),R.anim.blink);
Animation out = AnimationUtils.loadAnimation(getActivity(),R.anim.blink);
Test.setInAnimation(in);
Test.setOutAnimation(out);
return rootView;
}
我的 Fragment 布局有 TextSwitcher 的部分,我写的如下:
<TextSwitcher
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TEST">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textSize="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YES"
android:textSize="20dp"/>
</TextSwitcher>
Animation in = AnimationUtils.loadAnimation(this,android.R.anim.in);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.out);
switcher.setInAnimation(in);
switcher.setOutAnimation(out);
我想创建一个带有动画闪烁的 TextSwitcher。 当它消失时,应该更改文本。 这是我的眨眼
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="2000"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
包含 TextSwitcher 的我的片段
private TextSwitcher Test ;
public HomeFragment() {
// Required empty public constructor
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
Test = (TextSwitcher)rootView.findViewById(R.id.TEST) ;
Animation LeftSideAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.blink);
Animation in = AnimationUtils.loadAnimation(getActivity(),R.anim.blink);
Animation out = AnimationUtils.loadAnimation(getActivity(),R.anim.blink);
Test.setInAnimation(in);
Test.setOutAnimation(out);
return rootView;
}
我的 Fragment 布局有 TextSwitcher 的部分,我写的如下:
<TextSwitcher
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TEST">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textSize="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YES"
android:textSize="20dp"/>
</TextSwitcher>
Animation in = AnimationUtils.loadAnimation(this,android.R.anim.in);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.out);
switcher.setInAnimation(in);
switcher.setOutAnimation(out);