我是Android编程的新手,我正在使用自定义设计制作单词搜索游戏。是否可以在使用drawTextOnPath制作的拼图上应用动作事件?
这是我的设计代码。我声明字符串只是为了输出wordsearch网格的形状:
public class Game1 extends Activity {
TextView closep;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.game1);
RelativeLayout surface = (RelativeLayout) findViewById(R.id.middleSurface);
surface.addView(new GraphicsView(this));
ImageButton imagebutton1 = (ImageButton) findViewById(R.id.imageButton1);
imagebutton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
initiatePopupWindow();
}
});
}
PopupWindow pwindow;
protected void initiatePopupWindow() {
try {
LayoutInflater inflater = (LayoutInflater) Game1.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.pause_layout,
(ViewGroup) findViewById(R.id.playout));
pwindow = new PopupWindow(layout, 480, 800, true);
pwindow.showAtLocation(layout, Gravity.CENTER, 0, 0);
closep = (TextView) layout.findViewById(R.id.textBack);
closep.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
private OnClickListener cancel_button_click_listener = new OnClickListener() {
public void onClick(View v) {
pwindow.dismiss();
}
};
static public class GraphicsView extends View {
private final String O = "O O O O O O O O O O O O E V O L O O A C T I O N A L O O O O O O O O O O O O O O O O O O O";
private final String P = "O O O O O O O O O O O O O B O O M O O O O O O O O O O O O O O O O O O O O O O O O O O O O O";
private final String Q = "O O O O O O O O O O O O O O O O M O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O";
private final String R = "O O O O O O O O O O O O O O O O M O O O O O O O O O O O O O G O O G L E O O O O O O O O O O O O O";
private final String S = "O O O O O O O O O O O O O N O O M O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O";
private final String T = "O O O O O O O O O O O O O D O O M O O O O O O O O O O W A V E O O E G A G N E O O O O O O O O O O O O O O";
private final String U = "O O O O O O O O O O O O O M O O S E O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O";
/*
* private final char[] O_arr = O.toCharArray(); private final char[]
* P_arr = P.toCharArray(); private final char[] Q_arr =
* Q.toCharArray(); private final char[] R_arr = R.toCharArray();
* private final char[] S_arr = S.toCharArray(); private final char[]
* T_arr = T.toCharArray(); private final char[] U_arr =
* U.toCharArray();
*/
public GraphicsView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
this.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
float width = (float) getWidth();
float height = (float) getHeight();
float radius;
if (width > height) {
radius = height / 4;
} else {
radius = width / 4;
}
Path circle1 = new Path();
for (int i = 0; i < 1; i++) {
circle1.addCircle(width / 2, height / 2, radius + (i * 300),
Path.Direction.CW);
}
Path circle2 = new Path();
for (int i = 0; i < 1; i++) {
circle2.addCircle(width / 2, height / 2, radius + (i * 200),
Path.Direction.CW);
}
Path circle3 = new Path();
for (int i = 0; i < 1; i++) {
circle3.addCircle(width / 2, height / 2, radius + (i * 100),
Path.Direction.CW);
}
Path circle4 = new Path();
for (int i = 0; i < 1; i++) {
circle4.addCircle(width / 2, height / 2, radius + (i * 50),
Path.Direction.CW);
}
Path circle5 = new Path();
for (int i = 0; i < 1; i++) {
circle5.addCircle(width / 2, height / 2, radius + (i * 40),
Path.Direction.CW);
}
Path circle6 = new Path();
for (int i = 0; i < 1; i++) {
circle6.addCircle(width / 2, height / 2, radius + (i * 30),
Path.Direction.CW);
}
Path circle7 = new Path();
for (int i = 0; i < 1; i++) {
circle7.addCircle(width / 2, height / 2, radius + (i * 20),
Path.Direction.CW);
}
Paint paint = new Paint();
Paint xpaint = new Paint();
Paint ypaint = new Paint();
paint.setColor(Color.BLACK);
paint.setStrokeWidth(2);
paint.setStyle(Paint.Style.FILL);
paint.setTextSize(30);
paint.setTypeface(Typeface.SERIF);
xpaint.setColor(Color.BLACK);
xpaint.setTextSize(30);
xpaint.setStrokeWidth(2);
xpaint.setStyle(Paint.Style.FILL);
xpaint.setTypeface(Typeface.SERIF);
ypaint.setColor(Color.BLACK);
ypaint.setStyle(Paint.Style.FILL);
ypaint.setTextSize(30);
ypaint.setStrokeWidth(2);
ypaint.setTypeface(Typeface.SERIF);
canvas.drawTextOnPath(U, circle7, -5 / 4 * (-47), -5 / 4 * (-47),
ypaint);
canvas.drawTextOnPath(T, circle6, -5 / 4 * (-22), -5 / 4 * (-22),
ypaint);
canvas.drawTextOnPath(S, circle5, -5 / 4 * (3), -5 / 4 * (3),
ypaint);
canvas.drawTextOnPath(R, circle4, -5 / 4 * (25), -5 / 4 * (25),
ypaint);
canvas.drawTextOnPath(Q, circle3, -5 / 4 * (50), -5 / 4 * (50),
ypaint);
canvas.drawTextOnPath(P, circle2, -5 / 4 * (75), -5 / 4 * (75),
xpaint);
canvas.drawTextOnPath(O, circle1, -5 / 4 * (100), -5 / 4 * (100),
paint);
invalidate();
}
这是输出: https://app.box.com/s/iuiggyq53ny40roxfp5j037r049r7yjw
还有其他方法可以让它可玩吗?很高兴得到你的帮助。