android之动态创建控件

之前在网上找有关动态创建控件的帖子,发现没有几个人说的很明白;所以,决定自己写篇日志,将其说清楚。

动态创建控件,还是创 建控件;只不过,是在程序中创建控件;创建控件就好像在屏幕上画画一样。首先,要一张纸;然后,再在这个框架里画自己想画的事物。在android里,这 张纸就是一个容器,常用的LinearLayout、RelativeLayout、FrameLayout等等;在android里,自己想画的事物就 是一些view,常用的TextView、EditView、Button等等。
知道了大体思路之后,就要说细节了;
  第一是容器,创建一个容器(这里用LinearLayout举例);

第二是容器的细节,也就是属性部分;比如,容器里的控件是怎样排的;


第三是容器里的控件,创建自己想要的控件;比如,

第四是容器的细节,就是设置容器的属性;
第五是将控件加入到容器当中去;
  第六是将容器将加入ContentView中;
源代码:这个代码就不注释了,看了上面的六步应该会清楚下面的程序的

import org.cocos2dx.lib cannot be resolved

在使用 cocos2dx 的时候,建立的工程在编译的时候提示 import org.cocos2dx.lib cannot be resolved ,研究了研究发现,工程里面缺少了相应的Java代码,目录都已经建立好了,但是似乎拷贝脚本出了问题,没有把源文件拷贝进去

解决方法就是 ,找到 cocos2dx 的释放目录,在目录下找到 cocos2dx目录 下面找到 platform 目录下面有个android 目录 下面有个java目录,如下图了

我们在工程目录下面也看到一个类似的空目录

对应的目录拷贝进去就可以了

Android NativeActivity samples crashes

Log

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.
native_activity/android.app.NativeActivity}: java.lang.IllegalArgumentException
: Unable to find native library: native-activity

Answer

Over!

Type 'EGL_DEFAULT_DISPLAY' could not be resolved error while constant is clearly defined

I'm working on a native activity app for Android 2.3.3. I've copied the code from the code samples, I have include paths set, but Eclipse (Indigo) still can't find this constant.

EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);//Type 'EGL_DEFAULT_DISPLAY' could not be resolved

However the compiler shows no error:

Compile++ thumb  :NativeTest<=NativeTest.cpp

This error has to do with Eclipse not having __ ANDROID__ defined which makes it not define EGLNativeDisplayType in EGL/eglplatform.h which causes EGL_DEFAULT_DISPLAY to also not be defined.

To fix this go to your projects properties and go to the "C/C++ General->Paths and Symbols" page, under the "Symbols" tab click on GNU C and then the "Add" button and put

__ANDROID__

in the name feild and click OK. You can do the same for GNU C++.

The 'adb' tool is not in your path. You can change your PATH variable, or use --adb= to point to a valid one

The ndk-gdb script relies on setting the adb path, either by setting it as
an environment variable or
explicitly as a parameter of the script call.
Thus, there are two probable solutions:

1) set the PATH environment variable to point out your android sdk tools
folder (e.g. "export PATH=$PATH:<your_android_sdk_path_here>/tools")

or

2) invoke the ndk-gdb command with the path to the adb as a parameter (e.g.
: "ndk-gdb --adb=<your_android_sdk_path_here>/tools/adb")

keep in mind that the 1) solution will only work for your current terminal
session. If you want to persist this new PATH value, you must set it up
in the ~.MacOSX/environment.plist.

Ubuntu修改环境变量

Ubuntu Linux系统包含两类环境变量:系统环境变量和用户环境变量。系统环境变量对所有系统用户都有效,用户环境变量仅仅对当前的用户有效。

文章转载自http://leonhongchina.blog.163.com/blog/static/180294117201132611320112/

        修改用户环境变量

用户环境变量通常被存储在下面的文件中:

  •                 ~/.profile
  •                 ~/.bash_profile 或者 ~./bash_login
  •                 ~/.bashrc

上述文件在Ubuntu 10.0以前版本不推荐使用。

        系统环境变量

系统环境变量一般保存在下面的文件中:

  •                 /etc/environment
  •                 /etc/profile
  •                 /etc/bash.bashrc

/etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推荐使用。

        加入环境变量

如想将一个路径加入到$PATH中,可以像下面这样做(修改/etc/profile):

在里面加入:

你可以自己加上指定的多个路径,中间用冒号隔开。环境变量更改后,在用户下次登陆时生效,如果想立刻生效,则可执行下面的语句:

需要注意的是,最好不要把当前路径”./”放到PATH里,这样可能会受到意想不到的攻击。

            其他文件的修改方式与此类似,需要注意的是/etc/environment不需要使用export设置环境变量,其他profile文件需要。

更详细的说明可以参考这里

Android+Eclipse,创建项目总是出现 invalid project description. overlaps the workspace location的解决办法

创建或者导入工程的时候总是提示invalid project description. overlaps the workspace location错误,到处查资料最后找到解决办法,就是把新创建的工程目录设为非Eclipse得workspace目录,具体原因未知。

Ubuntu 12.04下"小米2"的真机调试

发现Ubuntu12.04不能连接小米开发,adb devices不能看到设备!  搞了一个上午才搞成功!

小米手机利用USB连接到Ubuntu 12.04系统。运行下面的命令:

拔掉手机的USB连接线,再运行:

对比发现,Bus 002 Device 028: ID 2717:904e    就是小米手机的

在打开的文件中增加以下文本:

注意,这个50-android.rules 文件名字应该是随意命名的,试过 51-android.rules ,52-android.rules  似乎是都可以的。

注意 "SUBSYSTEM=="usb", SYSFS{idVendor}=="2717", MODE=="0666" "这句是给 ubuntu 7.01 以后的系统识别用的

而"SUBSYSTEM=="usb_device", SYSFS{idVendor}=="2717", MODE=="0666""是给 Ubuntu 7.01之前的系统识别用的。相当于系统兼容。

在 android sdk 的 tools 目录下运行 (这一步很重要,必须要sudo,否则没效果)

到这一步了,结果发现 List of devices attached 下面没有设备出现,这就意味着 adb不识别新的USB 设备,纠结了。

如果跟我一样悲惨,请执行如下操作

请注意这个 adb_usb.ini

里面的内容一般如下:

我们在其中加一行

请注意,这个 0x2717 就是我们得到的设备号码

保存,关掉,然后

注意  9109ce53    device 这行就是我们的识别到的小米手机了。哈哈

然后在Eclipse下面的DDMS 去折腾吧。

gen already exists but is not a source folder. Convert to a source folder or rename it.

Android 代码中无意删除了 .setting文件夹,重建后提示

gen already exists but is not a source folder. Convert to a source folder or rename it.

查了半天,总算有个明白人

  1. Right click on the project and go to "Properties"
  2. Select "Java Build Path" on the left
  3. Open "Source" tab
  4. Click "Add Folder..."
  5. Check "gen" folder and click Ok and Ok again
  6. Again right click on the project and in the "Andriod Tools" click on "Fix Project Properties"