我在布局中有一个图像按钮,并实现相同的onclick功能。现在,我想在“点击”期间淡入图像按钮。如何在android中以编程方式淡入图像。提前致谢。Android - 淡入淡出图像按钮点击
1
A
回答
1
您需要在按钮上实现动画。您必须拥有包含alpha元素的View动画。阅读此:http://developer.android.com/guide/topics/resources/animation-resource.html,如果你需要任何帮助,请在这里写...
1
像这样(我还没有测试过,但应该工作),但你需要有“淡化”版本的ImageButton drawable。
Bitmap iconOn = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_on);//this should be yours faded button image
Bitmap iconOff = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_off); //and this will be normal image
Drawable iconOnDrawable = new BitmapDrawable(iconOn);
Drawable iconOffDrawable = new BitmapDrawable(iconOff);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_pressed },iconOnDrawable);
states.addState(new int[] { android.R.attr.state_focused },iconOffDrawable);
states.addState(new int[] { android.R.attr.state_selected },iconOnDrawable);
states.addState(new int[] {}, iconOffDrawable);
ImageButton imageButton = (ImageButton) findViewById(R.id.button);
imageButton.setImageDrawable(states);
0
这种方式是你怎么做:
Button b = view.findViewById(R.id.button);
final TransitionDrawable td = new TransitionDrawable(new Drawable[]{new ColorDrawable(0xFFFF0000), new ColorDrawable(0x11FF0000)});
b.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getActionMasked() == MotionEvent.ACTION_DOWN) {
//b.setBackgroundColor();
}
if(event.getActionMasked() == MotionEvent.ACTION_UP) {
b.setBackgroundDrawable(td);
td.startTransition(1000);
}
return false;
}
});
相关问题
- 1. Android图像按钮淡入淡出
- 2. 在淡入点击按钮淡出
- 3. android图像淡入淡出
- 4. 淡入淡出按钮单击
- 5. 淡入淡出按钮单击
- 6. 淡入淡出按钮单击
- 7. Android图像按钮淡出图像
- 8. javascript:淡入div按钮点击,然后第二个按钮点击淡出?
- 9. 淡入淡出iframe点击
- 10. 淡入()的点击()淡出()
- 11. Android - 淡入淡出/闪烁按钮
- 12. jQuery淡出当前图像,然后淡入点击的图像
- 13. 按顺序淡入淡出的图像
- 14. 在相同的按钮点击,Div淡出和淡入
- 15. jQuery - 淡入淡出之后点击外部,淡入淡出
- 16. 点击 - >淡入淡出 - > setTimout - >淡入淡出
- 17. jQuery的淡入淡出2个图像与缩略图点击
- 18. 淡入图像,淡出出图像
- 19. Javascript淡入淡出图像
- 20. 淡入淡出的图像
- 21. 图像淡入淡出
- 22. Javascript - 淡入淡出图像?
- 23. 淡入淡出图像?
- 24. jquery淡入/淡出图像
- 25. Javascript图像淡入淡出?
- 26. 点击按钮淡出弹出窗口?
- 27. Android:淡入淡出视图
- 28. 悬停和点击如何淡出图像和淡入淡出内容文字
- 29. 在指定按钮和不同按钮上点击淡入淡出
- 30. jquery淡入淡出对5个图像的影响点击
+1,谢谢,我得到了解决.... –