我已经用一个viewPager实现了一个具有四个选项卡的TabLayout。
每个选项卡都有一个customView,因为每个选项卡有两个textView(文本+未读计数)。
所以,当切换选项卡时,我能够处理很多UI方面的内容,但是我无法对未读的textView进行动画处理。
我的自定义XML文件中,针对textView及其父RelativeLayout,都设置了android:animateLayoutChanges="true"。
此外,我尝试在实际选项卡上设置此功能,并尝试了各种动画变化,但是没有一种有效。
PS- 没有动画的情况下,我只是设置了可见性(gone,visible),这种方法是起作用的。
我的自定义XML文件中,针对textView及其父RelativeLayout,都设置了android:animateLayoutChanges="true"。
此外,我尝试在实际选项卡上设置此功能,并尝试了各种动画变化,但是没有一种有效。
PS- 没有动画的情况下,我只是设置了可见性(gone,visible),这种方法是起作用的。
private void updateUnseenOnTab(int position, int unseen) {
ViewGroup vg = (ViewGroup) mTabLayout.getChildAt(0);
ViewGroup vgTab = (ViewGroup) vg.getChildAt(position);
View view = vgTab.getChildAt(0);
if (view != null && view.findViewById(R.id.tab_unseen) instanceof TextView) {
final TextView unseenText = (TextView) view.findViewById(R.id.tab_unseen);
if (unseen <= 0) {
unseenText.setText("0");
Animation fadeOut = new AlphaAnimation(0, 1);
fadeOut.setDuration(1000);
unseenText.setAnimation(fadeOut);
} else {
String currentText = unseenText.getText().toString();
try {
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setDuration(1000);
unseenText.setAnimation(fadeIn);
unseenText.setText("" + ((TextUtils.isEmpty(currentText) ? 0 : unseen) + Integer.valueOf(currentText)));
} catch (Exception e) {
e.printStackTrace();
}
}
}