如何使用进度条微调器显示AlertDialog?
按下按钮时,我希望它阻止UI,直到数据完成加载显示微调器和消息和标题.
我知道我需要使用asyncTask但是如何使用progressbar spinner显示对话框?
我在Andengine中使用此方法通过设置相机的偏移来滚动项目列表.
@Override
public void onScroll(ScrollDetector pScollDetector, int pPointerID,
float pDistanceX, float pDistanceY) {
//Disable the menu arrows left and right (15px padding)
if(mCamera.getXMin()<=15)
menuleft.setVisible(false);
else
menuleft.setVisible(true);
if(mCamera.getXMin()>mMaxX-15)
menuright.setVisible(false);
else
menuright.setVisible(true);
//Return if ends are reached
if ( ((mCurrentX - pDistanceX) < mMinX) ){
return;
}else if((mCurrentX - pDistanceX) > mMaxX){
return;
}
//Center camera to the current point
this.mCamera.offsetCenter(-pDistanceX,0 );
mCurrentX -= pDistanceX;
//Set the scrollbar with the camera
float tempX =mCamera.getCenterX()-CAMERA_WIDTH/2;
// add the % part to the position …Run Code Online (Sandbox Code Playgroud) 我试图使用jsoup解析这个内容.
<div class="imageInlineCenter" style="width: 468px;" align="center"><img src="http://xbox360media.ign.com/xbox360/image/article/117/1171345/MW3_3_468_1306710207.jpg" align="middle" border="0" height="263" width="468"><div class="inlineImageCaption" style="width: 468px;">Your subwoofer will get a break during the stealthy start of the 'Mind the Gap' level, but only briefly.</div></div>
Run Code Online (Sandbox Code Playgroud)
我只想解析img src标签来获取图片网址.
这就是我现在正在使用的...
try{
Elements img = jsDoc.select("div.imageInlineCenter");
String imgSrc = img.attr("img src");
System.out.println(imgSrc);
}
catch(Exception e){
Log.e("UPCOMING", "Couldnt retrieve the text");
}
Run Code Online (Sandbox Code Playgroud)
什么都没打印出来.相反,我得到它无法检索它的消息.
我怎么解析这个?
编辑:
这是我正在使用的代码.
它没有显示catch消息或system.out.
try {
jsDoc = Jsoup.connect(url).get();
try{
Elements img = jsDoc.select("div.imageInlineCenter img[src]");
String imgSrc = img.attr("src");
System.out.println(imgSrc);
}
catch(Exception e){
Log.e("UPCOMING", …Run Code Online (Sandbox Code Playgroud) 我正在使用此方法在AndEngine中将精灵移动到一侧.
Sprite player = new Sprite(PlayerX,PlayerY, this.mPlayerTextureRegion) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
final float pTouchAreaLocalX,
final float pTouchAreaLocalY) {
this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
this.getY());
return true;
}
};
Run Code Online (Sandbox Code Playgroud)
我注意到的问题是当精灵快速来回移动时会有延迟,有时它会一直移动,直到被修饰和拖动.
无论如何要优化它以获得更好的性能?
是否有人熟悉AndEngine并加载svg?
现在我正在尝试为场景加载背景,但由于某种原因它根本不会出现..
这是我用来加载SVG并将其附加到场景的代码.
//In my onLoadResources method
this.mBuildableTexture = new BuildableBitmapTexture(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
SVGTextureRegionFactory.setAssetBasePath("gfx/");
this.mSVGTestTextureRegions = SVGTextureRegionFactory.createFromAsset(this.mBuildableTexture, this, "background.svg", 16, 16);
//OnLoadScene method
final BaseTextureRegion baseTextureRegion = this.mSVGTestTextureRegions;
if(baseTextureRegion instanceof TextureRegion) {
final TextureRegion Region = (TextureRegion)baseTextureRegion;
final float centerX = this.mCamera.getWidth() / 2;
final float centerY = this.mCamera.getHeight() / 2;
final float x = centerX - SIZE * 0.5f;
final float y = centerY - SIZE * 0.5f;
Sprite backgroundSprite = new Sprite(x,y,SIZE,SIZE,Region);
/*protected void onInitDraw(final GL10 pGL)
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用AndEngine加载svg图像作为我的精灵.
我遇到的问题是我无法弄清楚如何缩放图像以适应运行它的特定设备.
sprite= new Sprite(positionX, positionY, WIDTH,HEIGHT,TextureRegion);
Run Code Online (Sandbox Code Playgroud)
它所采用的参数是x和y坐标上的位置,然后是宽度和高度.
我遇到的问题是我无法弄清楚如何根据我的需要将精灵缩放到正确的宽度和高度.
例如,我有一个标题,我希望标题在更大的设备上更大,我如何决定设备是否更大并将其扩展为更大的屏幕而缩小为更小的屏幕?
我正在使用LibGDX来创建一个新项目.
我想要做的是,我将tmx文件中的物体加载到工作正常的级别.身体也有一个精灵.
问题是,我是否想让用户触摸场景中的某些物体.当他们触摸身体时,他们将能够从场景中删除或删除它.
我不熟悉在libgdx中做这样的事情.虽然我确信它并不复杂.
无论如何我能在LibGDX中做到这一点吗?
编辑:
这是我到目前为止所拥有的.
QueryCallback callback = new QueryCallback() {
@Override
public boolean reportFixture(Fixture fixture) {
// if the hit fixture's body is the ground body
// we ignore it
// if the hit point is inside the fixture of the body
// we report it
hitBody = fixture.getBody();
return true;
}
};
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
hitBody = null;
return false;
}
Run Code Online (Sandbox Code Playgroud)
现在我只是不确定我如何删除被点击的身体..
我有一个加载图像的异步任务.我怎样才能在图库内部显示一个微调器,其中将加载图像以显示正在进行的一些工作?还是进度条?但我希望能够在不阻塞整个UI的情况下做到这一点.
我该怎么做呢?
我有这个创建的方法,每秒都会向我的andengine场景添加一个精灵.
private void createSpriteSpawnTimeHandler(){
TimerHandler spriteTimerHandler;
float mEffectSpawnDelay = 1f;
spriteTimerHandler = new TimerHandler(mEffectSpawnDelay,true,new ITimerCallback(){
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
addFace();
}
});
getEngine().registerUpdateHandler(spriteTimerHandler);
}
Run Code Online (Sandbox Code Playgroud)
我想做的是,例如
if(x <= b){
mEffectSpawnDelay = mEffectSpawnDely - .2f;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是当变量发生变化时.我无法找到更新TimeHandler的方法,让它知道更改mEffectSpawnDelay变量.
有什么建议?
我试图显示alertdialog但我一直收到此错误
01-24 21:52:45.640: E/AndroidRuntime(31119): FATAL EXCEPTION: UpdateThread
01-24 21:52:45.640: E/AndroidRuntime(31119): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
01-24 21:52:45.640: E/AndroidRuntime(31119): at android.os.Handler.<init>(Handler.java:121)
01-24 21:52:45.640: E/AndroidRuntime(31119): at android.app.Dialog.<init>(Dialog.java:100)
01-24 21:52:45.640: E/AndroidRuntime(31119): at android.app.AlertDialog.<init>(AlertDialog.java:96)
01-24 21:52:45.640: E/AndroidRuntime(31119): at android.app.AlertDialog$Builder.create(AlertDialog.java:891)
Run Code Online (Sandbox Code Playgroud)
它指向这条线
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
isGameRunning = false;
gameStarted = false;
mEngine.stop();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("How To Play");
builder.setIcon(R.drawable.ic_launcher);
final AlertDialog alert = builder.create(); //this line
builder.setPositiveButton("Thanks", new DialogInterface.OnClickListener() { …Run Code Online (Sandbox Code Playgroud)