4 つのタブに , を実装TabLayout
しました。viewPager
各タブcustomView
には が 2 つtextView
(テキスト + 非表示カウント) あるため、タブには があります。そのため、タブを変更するときに多くの UI を処理できますが、見えないものをアニメーション化することはできませんtextView
。
私のカスタム XML には、とその親android:animateLayoutChanges="true"
の両方があります。textView
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();
}
}
}