ObjectAnimator pixlated TextView

后端 未结 1 1756
终归单人心
终归单人心 2021-01-26 03:54

I face a problem when scaling up TextViews and Checkboxes in Samsung GT-N5110 android version 4.1.2 the following image appears after scaling up the TextView there\'s textview i

相关标签:
1条回答
  • 2021-01-26 04:47
    private int dp2px(float dp){
                return (int) (dp * activity.getResources().getDisplayMetrics().density + 0.5f);
            }
            private doScale(){
                final LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.test);
                final TextView textView = (TextView) linearLayout.findViewById(R.id.tv_main);
                final int oldSize = dp2px(30);
                final float scale = 2f;
                final float textSizeOld = textView.getTextSize();
                ValueAnimator valueAnimatorLarge = ValueAnimator.ofInt(1,100 );
                valueAnimatorLarge.setDuration(500);
                valueAnimatorLarge.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        ViewGroup.LayoutParams layoutParams = linearLayout.getLayoutParams();
                        float currentScale = (int)animation.getAnimatedValue()/100f;
                        layoutParams.width = (int) (scale*oldSize*currentScale);
                        layoutParams.height = layoutParams.width;
                        linearLayout.setLayoutParams(layoutParams);
                        textView.setTextSize(scale*textSizeOld*currentScale);
                    }
                });
                valueAnimatorLarge.start();
            }
    
    0 讨论(0)
提交回复
热议问题