按钮组?

时间:2012-03-14 14:04:03

标签: android animation button android-ui

我有一个问题 - 有没有办法将几个按钮定义为1组,并为该组制作1个动画,而不是为每个按钮创建单独的动画?

2 个答案:

答案 0 :(得分:1)

将它们全部放在ViewGroup中并为其设置动画。所有孩子都将成为动画的一部分。 ViewGroup是任何布局类的基类,这意味着您可以使用LinearLayout,RelativeLayout或其他任何您认为合适的布局类。

答案 1 :(得分:0)

您可以尝试设置onTouchListener上相同的所有按钮,例如:

 button1.setOnTouchListener(this);
 button2.setOnTouchListener(this);
 button3.setOnTouchListener(this);

当然,您的应用需要实现onTouchListener,然后您可以编写onTouchListener:

public void onClick(View v) {

// write your code what you want your buttons to do

// You can also write some different codes for buttons by using id
if(v.getId() == button1.getId())
{
      //do something when button1 clicked...
}

}
相关问题