我一直在寻找一个解决我的问题。但我的code似乎是确定。
I have been looking for a solution to my problem. But my code seems to be ok.
我会尽力解释:我已经与Android一个TextView:阿尔法=0在我的布局定义。我想(一单击图像时)显示的TextView与AlphaAnimation,从0.0至1.0F。
I'll try to explain: I have a TextView with android:alpha="0" in my layout definition. I want (when a image is clicked) show that TextView with an AlphaAnimation, from 0.0f to 1.0f.
我的问题是,当我点击图像,没有任何反应。但奇怪的是,如果我设置它的alpha 1在布局定义,我点击的形象,我可以看到动画(阿尔法1 - >阿尔法0 - >阿尔法1)。
My problem is that when I click the image, nothing happens. But the strange thing, is that if I set it's alpha to 1 in the layout definition, and I click the image, I can see the animation (alpha 1 -> alpha 0 -> alpha 1).
我是什么做错了吗?
我的code:
TextView tv = (TextView) findViewById(R.id.number);
AlphaAnimation animation1 = new AlphaAnimation(0.0f, 1.0f);
animation1.setDuration(1000);
animation1.setFillAfter(true);
tv.startAnimation(animation1);
在此先感谢。
Thanks in advance.
现在的问题是在安卓阿尔法=0
。此属性设置的视图透明度http://developer.android.com/reference/android/view/View.html#attr_android:alpha
The problem is in android:alpha="0"
. This property sets transparency of a View http://developer.android.com/reference/android/view/View.html#attr_android:alpha
当alpha属性等于0,那么动画改变的透明度从 0 * 0.0 = 0
到 0 * 1.0F = 0
。当alpha属性从设置为1,则动画正在改变透明度1 * 0.0 = 0
到 1 * 1.0F = 1
。这就是为什么在第一种情况下,你无法看到的文本,并在第二的一切工作正常。
When alpha property is equal to 0 then animation is changing transparency from 0*0.0f=0
to 0*1.0f=0
. When alpha property is set to 1 then animation is changing transparency from 1*0.0f=0
to 1*1.0f=1
. That's why in first case you can't see text and in the second everything works as expected.
为了让事情工作,你必须在布局XML可见性属性设置为不可见。并启动奥飞动漫呼叫前 tv.setVisibility(View.VISIBLE);
To make things work you have to set visibility property to invisible in layout xml. And before starting alpha animation call tv.setVisibility(View.VISIBLE);