我在我的Android应用程序中似乎无法更改
我在我的Android项目中使用IndoorAtlas库。我下载了示例应用程序并在手机上运行。效果很好。
此库具有一个
以下是示例提供的原始方法(对我来说工作正常):
以下是我用来更新
如果我将这些行添加到上面的
但是,如果我将这3行放在
我还注意到,如果在
这是我的
ImageView
的位置。这种情况发生在我将代码放置在特定方法中时,如下所述。我在我的Android项目中使用IndoorAtlas库。我下载了示例应用程序并在手机上运行。效果很好。
此库具有一个
onServiceUpdate
方法,用于处理位置更新。我的目标是在位置更新时移动ImageView
。非常简单。以下是示例提供的原始方法(对我来说工作正常):
/* IndoorAtlasListener interface */
/**
* This is where you will handle location updates.
*/
public void onServiceUpdate(ServiceState state) {
mSharedBuilder.setLength(0);
mSharedBuilder.append("Location: ")
.append("\n\troundtrip : ").append(state.getRoundtrip()).append("ms")
.append("\n\tlat : ").append(state.getGeoPoint().getLatitude())
.append("\n\tlon : ").append(state.getGeoPoint().getLongitude())
.append("\n\tX [meter] : ").append(state.getMetricPoint().getX())
.append("\n\tY [meter] : ").append(state.getMetricPoint().getY())
.append("\n\tI [pixel] : ").append(state.getImagePoint().getI())
.append("\n\tJ [pixel] : ").append(state.getImagePoint().getJ())
.append("\n\theading : ").append(state.getHeadingDegrees())
.append("\n\tuncertainty: ").append(state.getUncertainty());
log(mSharedBuilder.toString());
}
以下是我用来更新
ImageView
位置的代码:ImageView imgPoint = (ImageView) findViewById(R.id.imagePoint);
imgPoint.setX(250);
imgPoint.setY(200);
如果我将这些行添加到上面的
onServiceUpdate
方法中,该方法不起作用。 onServiceUpdate
方法中的任何内容都不会运行。但是,如果我将这3行放在
onCreate
或任何其他方法中,则可以正常工作。 ImageView
能够成功移动。我还注意到,如果在
onServiceUpdate
中添加一个Toast
或Alert
,同样的事情会发生。 onServiceUpdate
方法根本没有触发。Toast.makeText(getApplicationContext(), "Hello!",
Toast.LENGTH_LONG).show();
这是我的
activity_main.xml
文件。<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_weight="1">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="1dp"
android:layout_marginLeft="1dp"
android:id="@+id/imagePoint"
android:layout_weight="1" />
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>