3

4 つのタブに , を実装TabLayoutしました。viewPager各タブcustomViewには が 2 つtextView(テキスト + 非表示カウント) あるため、タブには があります。そのため、タブを変更するときに多くの UI を処理できますが、見えないものをアニメーション化することはできませんtextView

私のカスタム XML には、とその親android:animateLayoutChanges="true"の両方があります。textViewRelativeLayout

さらに、実際のタブでこの機能を設定しようとしましたが、アニメーションのバリエーションを試してみましたが、どれも機能しません。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();
            }
        }
    }
4

3 に答える 3

1

これはそのための良いライブラリです:

https://github.com/ToxicBakery/ViewPagerTransforms

これは開発者向けドキュメントです:

http://developer.android.com/training/animation/screen-slide.html

于 2015-07-18T19:01:35.927 に答える