我有一个游戏,其中有广告.我最终发现滞后的来源基本上是因为adRequest过程需要很长时间.
super.onCreate(savedInstanceState){
mainLayout = new LinearLayout(this);
mainLayout.setOrientation(LinearLayout.VERTICAL);
adView = new AdView(this, AdSize.BANNER, "MY_ID");
adView.setVisibility(AdView.VISIBLE);
mainLayout.addView(adView);
adView.loadAd(new AdRequest());
//more codes below
}
Run Code Online (Sandbox Code Playgroud)
我尝试做一些像创建一个线程,当有adRequest时会做一些loadAd.但导致广告不会显示.所以我认为loadAd请求必须在UI Thread中完成.这有什么解决方法吗?我仍然不了解UI Thread如何工作
这是我第一次尝试将我的libgdx项目打包到.apk文件中,我感到惊讶的是该文件比资产文件的总大小大2倍.assets文件夹应该是4MB但.apk文件变成8MB.我试图通过提取.apk文件来检查问题的根源.起初我以为是导致问题的库文件,但后来我检查它只需要1MB的内存.然后我发现资产文件夹中的图像和音乐文件夹被复制到外面并且占用了总大小的两倍.
这是我在eclipse项目中的android目录结构
-src
-gen
-asset
->image (30kB)
->musics (3MB)
->sfx (100kB)
-bin
-libs
-res
Run Code Online (Sandbox Code Playgroud)
这是.apk文件中的目录
-assets
->image (30kB)
->musics (3MB)
->sfx (100kB)
-com
-images (30kB)
-lib
-META-INF
-musics (3MB)
-res
-sfx (100kB)
Run Code Online (Sandbox Code Playgroud)
这里有没有人遇到过同样的问题?对此有何解决方案?谢谢
我想创建一个具有相同父类的对象的列表/数组,然后我将它用于参考.但我不知道如何克隆这些对象来制作一个新对象.
这是一个例子
BigFoo a;
SmallFoo b;
ChickenFoo c;
List<Foo> foos;
foos.add(a);
foos.add(b);
foos.add(c);
Foo foo = foos.get(1).clone();
Run Code Online (Sandbox Code Playgroud)
但在Java中我发现默认函数中没有克隆函数.我想知道这是如何实现的?
在这里,我有一个自定义对话框,里面有背景2 ImageButton.问题是,当我尝试将onclick监听器设置为该按钮时,程序将返回NullPointerException.我不知道为什么会这样.如何将操作分配给对话框内的按钮?
暂停菜单xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:background="@drawable/pause_menu_cropped" android:layout_gravity="center" android:gravity="center|center_horizontal">
<TableLayout android:layout_width="wrap_content" android:id="@+id/tableLayout1" android:layout_height="wrap_content">
<ImageButton android:src="@drawable/pause_button_option" android:layout_width="wrap_content" android:background="@drawable/pause_button_option" android:layout_height="wrap_content" android:id="@+id/btn_pause_option"></ImageButton>
<ImageButton android:src="@drawable/pause_button_quit" android:layout_width="wrap_content" android:background="@drawable/pause_button_quit" android:layout_height="wrap_content" android:id="@+id/btn_pause_quit"></ImageButton>
</TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
对话框代码
Dialog pauseMenu = new Dialog(this, R.style.NewDialog);
pauseMenu.setContentView(R.layout.pause_menu);
ImageButton quit = (ImageButton)findViewById(R.id.btn_pause_quit);
quit.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
TestActivity.this.finish();
}
});
return pauseMenu;
Run Code Online (Sandbox Code Playgroud)
代码返回错误
quit.setOnClickListener();
Run Code Online (Sandbox Code Playgroud) 是否有任何可能的方法来迭代R.raw或R.drawable或任何R类?我想动态地获取该文件夹上的每个id.
ArrayList resArray = new ArrayList();
foreach(int id : R.raw) {
resArray.add(id);
}
Run Code Online (Sandbox Code Playgroud)
或者还有其他方法吗?
使用SharedPreference我无法理解.
在本文档中,它说API 1支持getStringSet()方法.但我没有找到类似的方法.我为我的应用程序使用API 8.这里发生了什么事?它不再受支持吗?
ps:与SharedPreference.Editor没有区别.编辑器类中没有putStringSet().
截图:看..没有getStringSet()

我想知道这段代码是否会导致内存泄漏?因为我还是不知道什么时候应该处理一个纹理.纹理应该放在方法的最后?或未使用后单独处理?
private void loadAssets() {
Texture texture = new Texture(Gdx.files.internal("data/controls.png"));
TextureRegion[] buttons = TextureRegion.split(texture, 64, 64)[0];
left = buttons[0];
right = buttons[1];
jump = buttons[2];
cubeControl = buttons[3];
cubeFollow = TextureRegion.split(texture, 64, 64)[1][2];
dpad = new TextureRegion(texture, 0, 64, 128, 128);
batch = new SpriteBatch();
batch.getProjectionMatrix().setToOrtho2D(0, 0, 480, 320);
}
Run Code Online (Sandbox Code Playgroud)
我真的不明白 为什么Java中仍然存在内存泄漏?
我有一个具有surfaceview并在线程上运行的游戏.如果我在游戏的时候按下HOME按钮,然后我再次通过图标打开游戏,我会收到一个力量.可能是什么问题?