首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ObjectAnimator像素化TextView

ObjectAnimator像素化TextView
EN

Stack Overflow用户
提问于 2016-03-28 15:28:00
回答 1查看 930关注 0票数 0

当我放大TextViews和三星GT 5110安卓版本4.1.2的复选框时,会遇到一个问题。下面的图片在放大TextView后出现,我想放大它,我尝试了在开发人员选项中启用缩放动画,但没有用,我也尝试了nineoldandroid.jar。

下面是我在虚拟场景中的代码:

代码语言:javascript
复制
@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();
        }

布局:

代码语言:javascript
复制
 <?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:

代码语言:javascript
复制
<?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>

更新:

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

EN

回答 1

Stack Overflow用户

发布于 2016-03-28 16:11:23

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36265448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档