本文介绍了ObjectAnimator pixlated的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

扩大三星GT-N51​​10的Andr​​oid 4.1.2版TextViews和复选框,当我面对的一个问题
下图显示向上扩展的TextView后有TextView的里面我想扩展它我也尝试让开发者在选择规模的动画没有用我也没有尝试nineoldandroid.jar。

这是我的code里面fargment:

  @Nullable
    @覆盖
    公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
        鉴于= inflater.inflate(R.layout.test,集装箱,FALSE);
        的LinearLayout =(的LinearLayout)view.findViewById(R.id.test);
        的TextView =(AutoResizeTextView)view.findViewById(R.id.text);
        返回视图。
    }
    @覆盖
        公共无效调用onStart(){
            super.onStart();
     ObjectAnimator.ofFloat(的LinearLayout的scaleY,500).setDuration(500)。开始();
        ObjectAnimator.ofFloat(LinearLayout中,将scaleX,500).setDuration(500)。开始();
        }

布局:

 <?XML版本=1.0编码=UTF-8&GT?;
    < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:方向=垂直>
        <的LinearLayout
            机器人:ID =@ + ID /测试
            机器人:layout_width =30dp
            机器人:layout_height =30dp
            机器人:layout_gravity =中心
            机器人:背景=@绘制/ prayer_background>            < com.example.views.AutoResizeTextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =中心
                机器人:文字=@字符串/关于我们
                机器人:TEXTSIZE =5SP/>        < / LinearLayout中>
    < / LinearLayout中>

prayer_background:

 <?XML版本=1.0编码=UTF-8&GT?;    <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:造型=椭圆形>
        <角落的an​​droid:半径=10dip/>
        <中风
            机器人:宽=5dip
            机器人:颜色=@色/ mainColor/>
        [固体机器人:色=@色/ mainColor/>
    < /形状>

更新:

我曾尝试AutoResizeText和ScaleableTextView提到的here:
我得到以下结果:


解决方案

 私人诠释dp2px(浮点DP){
            回报(INT)(DP * activity.getResources()getDisplayMetrics()密度+ 0.5F);
        }
        私人doScale(){
            最终的LinearLayout的LinearLayout =(的LinearLayout)view.findViewById(R.id.test);
            最终的TextView的TextView =(TextView中)linearLayout.findViewById(R.id.tv_main);
            最终诠释oldSize = dp2px(30);
            最终浮动规模= 2F;
            最终浮动textSizeOld = textView.getTextSize();
            ValueAnimator valueAnimatorLarge = ValueAnimator.ofInt(1,100);
            valueAnimatorLarge.setDuration(500);
            valueAnimatorLarge.addUpdateListener(新ValueAnimator.AnimatorUpdateListener(){                @覆盖
                公共无效onAnimationUpdate(ValueAnimator动画){
                    ViewGroup.LayoutParams的LayoutParams = linearLayout.getLayoutParams();
                    浮动currentScale =(INT)animation.getAnimatedValue()/ 100F;
                    layoutParams.width =(INT)(*规模* oldSize currentScale);
                    layoutParams.height = layoutParams.width;
                    linearLayout.setLayoutParams(的LayoutParams);
                    textView.setTextSize(规模* textSizeOld * currentScale);
                }
            });
            valueAnimatorLarge.start();
        }

I face a problem when scaling up TextViews and Checkboxes in Samsung GT-N5110 android version 4.1.2the following image appears after scaling up the TextView there's textview inside i want to scale it up i did try enabling scale animation in developer options with no use i also did try nineoldandroid.jar.

here's my code inside fargment:

@Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.test, container, false);
        linearLayout = (LinearLayout) view.findViewById(R.id.test);
        textView = (AutoResizeTextView) view.findViewById(R.id.text);
        return view;
    }


    @Override
        public void onStart() {
            super.onStart();
     ObjectAnimator.ofFloat(linearLayout , "scaleY", 500).setDuration(500).start();
        ObjectAnimator.ofFloat(linearLayout , "scaleX", 500).setDuration(500).start();
        }

layout:

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


        <LinearLayout
            android:id="@+id/test"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:background="@drawable/prayer_background">

            <com.example.views.AutoResizeTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/aboutUs"
                android:textSize="5sp" />

        </LinearLayout>
    </LinearLayout>

prayer_background:

<?xml version="1.0" encoding="utf-8"?>

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <corners android:radius="10dip" />
        <stroke
            android:width="5dip"
            android:color="@color/mainColor" />
        <solid android:color="@color/mainColor" />
    </shape>

Update:

I did try AutoResizeText and ScaleableTextView mentioned here:I get the following result:

解决方案
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();
        }

这篇关于ObjectAnimator pixlated的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 21:13