我在中爲環形女巫創建了N個按鈕。用戶可以點擊每個按鈕並設置一個數字。在那之後,我想要一個TextView
顯示剛剛在按鈕上方和中間的數字。動態獲取並設置位置
這正是我想要的。灰色背景是按鈕,數字是TextView
。
的代碼,我現在所擁有的:
for (int toShow = 0; toShow < nShips; toShow++)
{
btn = new Button(this);
btn.setBackgroundResource(shipDrawable.get(ima));
btn.setLayoutParams(params);
row[pos].addView(btn);
btn.setId(shipId.get(ima));
btn.setOnClickListener(listeners);
if (row[pos].getChildCount() == 3) pos++;
ima++;
}
我試着用這裏面的for循環:
float x = btn.getX(), y = btn.getY();
TextView level = new TextView(this);
level.setText("5");
level.setX(x); level.setY(y);
但沒有奏效。我可以用什麼來獲得我想要的東西?
爲什麼在Button.setText()中不使用文本? – Arslan 2012-03-26 08:55:12
因爲我只是想顯示圖像 – 2012-03-26 09:15:12
然後你應該使用ImageButton – Arslan 2012-03-26 09:21:46