我已经TabLayout
用viewPager
, 实现了四个选项卡。选项卡有一个customView
, 因为每个选项卡有两个textView
(文本 + 看不见的计数)。因此,我可以在更改选项卡时处理很多 UI 内容,但是,我无法为看不见的textView
.
我的自定义 XMLandroid:animateLayoutChanges="true"
对textView
和它的 parent都有RelativeLayout
。
另外,我已经尝试在实际选项卡上设置此功能,尝试了各种动画,但均无效。Ps - 没有动画,我只是设置可见性(消失,可见),这是可行的。
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();
}
}
}