我正在使用SQLite和phonegap来创建一个多平台应用程序.但是,我遇到了一个问题.
现在我正在寻找的位置PhoneGap的存储数据库文件命名0000000000000001.db和database.db
我已经为iPhone找到了这个,但似乎无法获得Android的位置.我目前正在运行模拟器和实际设备(ARCHOS).
我正在使用phonegap,并试图检测onClick,但Android似乎完全忽略它,下面是我正在尝试:
<select name="func" onclick="StartButtons();" data-native-menu="true">
Run Code Online (Sandbox Code Playgroud)
我已经尝试过onClick的几种变体包括javascript,jQuery等等.但是这些似乎都不起作用.
我注意到onChange有效,但这对我没有多大用处,因为我需要使用一个提示,要求用户确认更改,如果不是那么什么都不做.但是,使用onchange仍会更改下拉列表中的项目.
有人可以帮忙吗?
我在修复index.html页面的屏幕方向时遇到问题.我想允许应用程序旋转,除了在主页上.我明白将以下内容添加到您的活动中 - android:screenOrientation ="portrait"会阻止屏幕旋转.
但是,我需要设置它,以便它是特定于页面的.我正在使用phonegap,因此需要停止我的网页浏览页面.
我尝试在我的清单中调用以下活动 - com.phonegap.droidgap.index.html,但这不起作用.
有人可以建议我如何定义1页的固定方向吗?
提前致谢
我有一个复杂的Battle系统,它有1个父Activity,然后是几个子类,通过扩展Battle并将上下文传递给这些类来访问BattleActivity的静态变量.
这一切似乎都运行正常,但是我在从内存中释放所有的AnimationDrawables时遇到了问题.在整个战斗中总共可以使用24个DrawableAnimations.现在这是可以的,但是每次用户遇到一个新的怪物时,就会有4个以上的AnimationDrawables被添加到内存中,这将慢慢地使得我的应用程序崩溃,并且内存不足异常.
因此,我真的需要找到一种方法来释放我的战斗系统在我退出时占用的所有内存.目前,我正在测试Sony Z2,当用户参加战斗时,记忆从91mb增加到230mb.当战斗迫使我需要将这个内存使用量降低到91mb.我添加了一些非常基本的代码片段,让您了解应用程序当前的流程以及我尝试释放内存的方法.
public class Battle extends Activity
{
// I have several AnimationDrawables loaded into memory
// These are then assigned the relevent animation to a button swicthing between these animations throughout my battle
ImageButton btnChr1;
AnimationDrawable cAnimHit1;
}
//This is the use of one of those AnimationDrawables
public class Battle_Chr_Anim extends Battle
{
protected Context ctx;
private ImageButton btnChr1;
AnimationDrawable cAnimHit1;
public Battle_Chr_Anim(Context c, ImageButton _btnChr1, AnimationDrawable _cAnimHit1) {
this.ctx = c;
this.btnChr1 = _btnChr1;
this.cAnimHit1 = …Run Code Online (Sandbox Code Playgroud) java android memory-leaks memory-management animationdrawable
我正在绘制一个缩放的位图到画布上,并希望在指定的时间淡出我的图像.
基本上,当我的角色图像越过画布的某个部分时,我要求角色图像在页面自动重定向到下一个java类之前慢慢淡出(3秒).
目前,我的图像只是重定向到新的java类,请参阅下面的一些代码,了解我如何创建我的图像.
Resources res = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, res.getDisplayMetrics());
imgSpacing = (int) px / 2;
int size = (int) ((PhoneWidth / 5) - px);
chrImg = BitmapFactory.decodeResource(getResources(), R.drawable.character);
chrImg = Bitmap.createScaledBitmap(chrImg, size, size, true);
Run Code Online (Sandbox Code Playgroud)
然后在画布上绘制:
if(indexX == mazeFinishX && indexY == mazeFinishY)
{
canvas.drawBitmap(finish, j * totalCellWidth, i * totalCellHeight, null);
// As soon as the character moves over this square they are automatically re-directed to new page
// This is where I want to fade …Run Code Online (Sandbox Code Playgroud) 由于ghostCoder暗示了检测触摸事件而不是点击事件的想法,我接近制定解决方案.下面的代码是我目前所拥有的,但有些东西仍然不太正确.它可以在我的主页(非常基本的页面)上工作,但是实际的游戏页面会破坏:
这是我的代码:JAVASCRIPT:
var b=document.getElementById('STOP'),start=0;
//Check for touchstart
if('ontouchstart' in document.documentElement)
{
document.getElementById("notouchstart").style.display = "none";
}
//Add a listener that fires at the beginning of each interaction
[b].forEach(function(el){el.addEventListener('touchstart',interact);});
//Add the event handlers for each button
b.addEventListener('touchstart',highlight);
//Functions Store the time when the user initiated an action
function interact(e)
{
start = new Date();
}
//Highlight what the user selected and calculate how long it took the action to occur
function highlight(e)
{
e.preventDefault();
e.currentTarget.className="active";
if(start)
{
alert("test")
}
start = null; …Run Code Online (Sandbox Code Playgroud) 我目前有一个5 x 5平方的迷宫游戏(占用屏幕宽度并均匀分割).然后,对于使用x和y坐标的每个框,我使用drawRect来绘制彩色背景.
我遇到的问题是我现在需要在同一位置绘制图像,因此替换当前的普通背景颜色填充.
这是我目前用于drawRect的代码(一些例子):
// these are all the variation of drawRect that I use
canvas.drawRect(x, y, (x + totalCellWidth), (y + totalCellHeight), green);
canvas.drawRect(x + 1, y, (x + totalCellWidth), (y + totalCellHeight), green);
canvas.drawRect(x, y + 1, (x + totalCellWidth), (y + totalCellHeight), green);
Run Code Online (Sandbox Code Playgroud)
然后我还需要为画布中的所有其他方块实现背景图像.此背景将在其顶部绘制简单的1px黑色线条,当前代码以灰色背景绘制.
background = new Paint();
background.setColor(bgColor);
canvas.drawRect(0, 0, width, height, background);
Run Code Online (Sandbox Code Playgroud)
如果可能的话,请你指点一下.如果是这样,那么我可以做的最好的方法是什么,同时尽量减少内存使用量并使1个图像扩展和缩小以填充相关的方形空间(这会因所有不同的屏幕尺寸而变化,因为它会分裂整体屏幕宽度均匀).
一些背景:
我正在创建一个Android游戏,在背景图像的画布上绘制迷宫,这使用方块,因此迷宫总是自动放大到5 x 5平方,迷宫可能是20 x 20.通过简单地运行一组for循环然后在相关位置绘制线来绘制迷宫.这一切都很完美,但是我的问题是让我的onDraw顺利运行.这是因为每次我无效的事实我必须重新运行for look并运行各种if语句来检查位置(不幸的是这个过程无法改进).
问题:
我想重新编写我的迷宫画在画布上的方式,下面是我需要实现的3个主要功能:
1 - 将整个迷宫绘制到画布上(这很容易)2 - 放大迷宫,只显示5 x 5 3 - 移动角色(总是在屏幕中心)并绘制下一个区域迷宫
现在如上所述绘制整个迷宫很容易,并且会使onDraw显着更快,因为它们不需要在invaldate上运行for循环,它可以在首次加载时执行一次.
就第2点和第3点而言,我看到这个工作的方式是在画布中间绘制的字符,然后是附加/链接到字符移动的2d鸟眼视图相机.此相机还需要放大到只显示整个迷宫网格的5 x 5的程度.然后当charcater移动时,相机随角色移动并显示已经绘制的迷宫的下一部分.我已经尝试了一些事情并做了一些研究但是我之前从未使用过画布,也不知道从哪里开始,如果这是可能的话.
因此,总结问题的主要部分是它们是否是将鸟眼视图相机链接到放大并随角色图像移动的角色的方式.
下面是关于如何绘制迷宫的片段,使用2组for循环检查2组布尔数组[] [],它只存储要绘制的垂直和horixaonl线.
@Override
protected void onDraw(Canvas canvas)
{
canvas.drawRect(0, 0, width, 100, background);
RectBackground.set(0,0, FullScreenWidth, FullScreenWidth);
canvas.drawBitmap(gameBackground, null, RectBackground, null);
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 5; j++)
{
float x = j * totalCellWidth;
float y = i * totalCellHeight;
indexY = i + currentY;
indexX …Run Code Online (Sandbox Code Playgroud) 当我在Xerces库中导入时,我似乎无法构建我的应用程序.由于之前的问题,我已经在使用multidex,因此我知道这一切都已正确设置.
我花了几天时间在线查看并尝试各种版本的Xerces并调整到我的build.gradle但无法解决问题.我已经尝试过清理重建,重新设置Android Studio /我的PC,使用jar直接编译,现在正式出于想法.
下面是我的build.gradle设置:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "#packageid#"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "0.8"
multiDexEnabled true
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'me.dm7.barcodescanner:zbar:1.8.4'
compile project(':rangebar-1.3')
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
}
compile 'com.batch.android:batch-sdk:1.5'
compile 'xerces:xercesImpl:2.11.0' …Run Code Online (Sandbox Code Playgroud) 我有一个触发1对话框的游戏视图,从这里触发第二个对话框.
在第二个对话框中,我有2个按钮和1个微调器.我遇到的问题是让一个微调器出现在我的视图中,带有动态数据.
基本上,我需要在单击按钮时弹出窗口并列出所有相关数据.我有3个不同的ArrayLists(1个String和2个整数),它们包含需要动态添加到每个微调器选择的sepearte信息,例如
pt1 - ArrayLists1
ArrayLists2
ArrayLists3
pt2 - ArrayLists1
ArrayLists2
ArrayLists3
Run Code Online (Sandbox Code Playgroud)
Spinner XML布局代码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<Button android:text="@string/attack"
android:id="@+id/Attack"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:text="@string/useitem"
android:id="@+id/UseItemBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Spinner android:text="@string/useitem"
android:id="@+id/UseItemSpin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<Button android:text="@string/equipweapon"
android:id="@+id/EquipWeapon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我当前用来触发微调器点击的代码(此处的日志被触发):
import android.widget.AdapterView.OnItemSelectedListener;
@Override
public void onClick(View clicked)
{
if(clicked.getId() == R.id.UseItemBtn)
{
Spinner spinner = (Spinner) findViewById(R.id.UseItemSpin);
ArrayList<String> arrayList1 = new ArrayList<String>();
arrayList1.add("test item the first one");
arrayList1.add("really long list item - section …Run Code Online (Sandbox Code Playgroud) 我希望创建一个类似控制器的模拟器,以便在xml布局中移动我的角色(这看起来与PlayStation或Xbox控制器上的类似 - 圆形模拟).
我的第一个计划是简单地使用图像视图并在图像视图上放置4个透明按钮以允许移动,但是这有点沉闷并且想要真正有创意,但是我很难找到任何类型的文档并不确定从哪里开始.
基本上,我所追求的功能是一个看起来像模拟的图像(见下文),然后用户可以按下并移动动画,这将触发相关的位置移动.理想情况下,我也想拥有这个,这样用户只需点击模拟上的右侧即可自动动画,然后触发正确的动作.

我不确定这是否可行,我要求在我的xml布局中实现,或者如果更容易,可以通过编程方式创建.
我尝试了各种不同的东西,但它们似乎都没有用.我正在使用内联CSS,只是想添加一个背景,以适应屏幕尺寸.我目前在我的body标签中使用以下代码:
<body onLoad="onBodyLoad();" style="background:url(images/blue_bg.png);">
Run Code Online (Sandbox Code Playgroud)
我的图像是400 x 300,但需要拉伸至1200 x 1000.
希望有人可以提供帮助(尝试过背景:100%).
谢谢,
android ×11
java ×7
cordova ×5
javascript ×3
bitmap ×2
html ×2
camera ×1
css ×1
database ×1
draw ×1
dynamic ×1
fadeout ×1
game-physics ×1
gradle ×1
image ×1
layout ×1
memory-leaks ×1
orientation ×1
spinner ×1
sqlite ×1
timer ×1
xerces ×1
xml ×1
xml-parsing ×1