我似乎无法改变一个人的立场ImageView
在我的安卓应用程序中。当我将代码放置在特定方法中时,就会发生这种情况,如下所述。
我正在使用室内图集 http://www.indooratlas.com/我的 android 项目中的库。我下载了示例应用程序并让它在我的手机上运行。效果很好。
这个图书馆有一个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
是能够成功移动的。
我还注意到,如果我添加一个Toast
or Alert
in onServiceUpdate
,同样的事情发生。这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>