我想创建一个带动画闪烁的TextSwitcher。 当它消失时,应该改变文本。 这是我的Blink
<?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>
My Fragment包含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;
}
My 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>
答案 0 :(得分:3)
Animation in = AnimationUtils.loadAnimation(this,android.R.anim.in);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.out);
switcher.setInAnimation(in);
switcher.setOutAnimation(out);