【发布时间】:2015-02-13 11:14:41
【问题描述】:
在 imageAdapter 类中,我在 try/catch 中将图像 alpha 设置为 0.5 handler.imageView.setAlpha(0.5f);。
它是这样制作的,而不是在布局xml中,因为之前版本的android有int而不是float,所以,在catch中,setAlpha是128。
在活动中,我有一个AlphaAnimation(float from, float to),因此我可以在项目之间滑动时进行更平滑的过渡。我将from = 0.5f 设置为与初始值匹配,将to = 1.0f 设置为完全不透明的图像。我真的从中获得了一部分。未选中的项目显示 0.5 的 alpha,但是当它被选中时,它不是 100% 不透明的,只是多一点。
活动代码:
private View antView = null; //Last view seen
...
gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
if(antView != null)
setItemViewMode(antView, false);
antView = v;
setItemViewMode(v, true);
}
});
//This method is to detect the item selected, and change styles to selected and the view from before
public void setItemViewMode(View item, boolean selected) {
Animation animationImage;
ImageView img = (ImageView) item.findViewById(R.id.imageView1);
if(selected) {
animationImage = new AlphaAnimation(0.5f, 1.0f);
}
else {
animationImage = new AlphaAnimation(1.0f, 0.5f);
}
animationImage.setDuration(250);
animationImage.setFillAfter(true);
img.startAnimation(animationImage);
}
如上所述,动画发生了,但是所选图像的 alpha 不是 100% 不透明的。
在动画中设置不透明度可能有问题吗?
【问题讨论】:
-
您想要 0.0f 到 1.0f 还是 0.5f 到 1.0f?
-
the image starts with 0.5f and when selected changes from that value to 1.0f to see it full opaque, so I understand that starts from 0.5f in the animation
-
对,你试过设置插值器吗?
-
不,我是android dev的新手,所以我会一点一点地按照他们告诉我的去做。
标签: android animation opacity alpha