安卓2048的卡片类

public class card extends FrameLayout
{
	private int number = 0;
	private TextView lable;

	public card(Context context)
	{
		super(context);
		lable = new TextView(getContext());
		lable.setTextSize(32);
		lable.setGravity(Gravity.CENTER);
		LayoutParams lp = new LayoutParams(-1, -1);// 填充满整个父级容器
		lp.setMargins(10, 10, 0, 0);
		addView(lable, lp);
		lable.setBackgroundColor(Color.GREEN);
		// TODO Auto-generated constructor stub
	}

	public int getNumber()
	{
		return number;
	}

	public void setNumber(int number)
	{
		this.number = number;
		if (this.number == 0)
		{
			lable.setText("");
			return;
		}
		lable.setText(number + "");
	}

	public boolean equals(card o)
	{
		// TODO Auto-generated method stub
		return getNumber() == o.getNumber();
	}
}

你可能感兴趣的:(安卓2048的卡片类)