Android放大中心对齐文字的各个方向

时间:2014-08-08 18:16:34

标签: android animation

我有一个xml布局

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical"
            android:textAlignment="center" >

            <TextView
                android:id="@+id/myidtv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center" />

            <TextView                    
                android:text="mytext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>

我想创建动画,将TextView中的文本从50%扩展到100%,但文本应该从头到尾保留在中心。

我尝试使用以下代码,但动画不以文本为中心开始。

ScaleAnimation animation = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, Animation.RELATIVE_TO_PARENT, (float)1, Animation.RELATIVE_TO_SELF, (float)1);

感谢您的帮助

2 个答案:

答案 0 :(得分:1)

问题是构造函数。这是解决方案。不管怎样,谢谢。

    ScaleAnimation animation = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.51);

答案 1 :(得分:0)

将TextView的重力设置为居中将使内容在TextView中居中。您可以尝试将外部LinearLayout的重力设置为居中。