简体   繁体   English

Android程序修改

[英]Android Program Modification

I'm currently working on my first android project, which is to modify an existing sample program ("Tic Tac Toe" game). 我目前正在开发我的第一个android项目,该项目是修改现有的示例程序(“井字游戏”)。 I'm going through the tutorials on the official website, but looking at the sample code I don't think I'll be able to figure everything out on my own in the time I have. 我正在浏览官方网站上的教程,但查看示例代码,我认为我无法在自己有空的情况下自行解决所有问题。

The modifications include being able to select a custom background, setting up a scoring system, and implementing a timed "blitz" mode. 修改包括能够选择自定义背景,设置评分系统以及实现定时的“闪电战”模式。 My basic questions are: 我的基本问题是:

  1. In which subfolder would the code that sets the background color/image for the game be? 设置游戏背景颜色/图像的代码在哪个子文件夹中?

  2. Is there a way to create an Intent function that opens up a file search window to allow a user to select this custom background image? 有没有一种方法可以创建一个Intent函数来打开文件搜索窗口,以允许用户选择此自定义背景图片?

I'd like to start here, I'm sure I'll have more questions as I go along. 我想从这里开始,我相信我会继续遇到更多问题。 As always, any help is appreciated. 与往常一样,我们将提供任何帮助。 (By the way, the code from the game is from the standard sample problems that come installed with the Android SDK for Eclipse). (顺便说一下,游戏中的代码来自Eclipse的Android SDK随附的标准示例问题)。

Update 1: 更新1:

So far I found this in a class called GameView: 到目前为止,我在名为GameView的类中发现了这一点:

mDrawableBg = getResources().getDrawable(R.drawable.lib_bg);
 setBackgroundDrawable(mDrawableBg);

mDrawableBg is a Drawable object, I'm not sure what this part is refrencing: mDrawableBg是一个Drawable对象,我不确定这部分在引用什么:

R.drawable.lib_bg

What would be the proper way to modify the background in this piece of the code? 在这段代码中修改背景的正确方法是什么?

Update 2: 更新2:

Here's where I'm at: 我在这里:

I have the getDrawable function taking another function as an argument: 我有将另一个函数作为参数的getDrawable函数:

mDrawableBg = getResources().getDrawable(getImage());   

getImage() is suppose to return a integer referencing the selected image, here is the code (so far) for that function: getImage()假定返回一个引用所选图像的整数,这是该函数的代码(到目前为止):

public int getImage(){

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
    intent.setType("image/*");
    startActivityForResult(intent, 10);

}

This is suppose to open the gallery and let the user select an image, I'm not sure how to return a reference ID to that selected image though. 假设是要打开图库并让用户选择图像,但是我不确定如何将参考ID返回给该选定图像。 Also, the startActivityForResult function is not working properly, I don't think I'm using the Activity class properly. 另外,startActivityForResult函数无法正常工作,我认为我没有正确使用Activity类。

  1. The background is probably defined as either a drawable (in /res/drawable-* ) or a color value (in /res/values/colors.xml or something like that). 背景可能定义为drawable(在/res/drawable-* )或颜色值(在/res/values/colors.xml或类似的东西中)。 It will be referenced in one of the layout files in /res/layout . 将在/res/layout中的布局文件之一中引用它。 The layout file will be referenced by one of the activity classes in the Java source folders. Java源文件夹中的活动类之一将引用布局文件。

  2. You can declare in code an array of drawable resource IDs and use that to dynamically generate a dialog and/or activity. 您可以在代码中声明可绘制资源ID的数组,并使用该数组动态生成对话框和/或活动。 The HorizontalScrollView widget might be useful for this. Horizo​​ntalScrollView小部件可能对此有用。 If you start a selection activity with an intent, use startActivityForResult instead of startActivity . 如果您有意启动选择活动,请使用startActivityForResult而不是startActivity You can then set the background of your top view using setBackgroundResource() . 然后,您可以使用setBackgroundResource()设置顶视图的背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM