1

首先,很抱歉布局不佳,这是我第一次提出问题。我已经对这个问题进行了搜索,但找不到解决方案。

现在,对于我的项目,我必须在地图对象上添加一个标识。它工作正常,我可以获得我想要获得的结果。但是当我想在视图上显示识别任务的结果时会出现问题。

我在 XML 文件中设置了 RelativeLayout 的样式,这是代码段。由于不相关,我已经删除了很大一部分。布局包含 4 个字段,我将只显示其中一个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/basic"
tools:context=".HelloWorldActivity" >

<com.esri.android.map.MapView
    android:id="@+id/map"
    style="@style/basic"
    initExtent = "-1849.3798815878108 139037.2620862738 219078.1453067956 241431.21687418327">
</com.esri.android.map.MapView>

<RelativeLayout
    android:id="@+id/objectInfo"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    style="@style/objectInfo" >

    <TextView
        android:id="@+id/labelStatus"
        style="@style/labelProperty"
        android:text="@string/labelStatus" />

    <TextView
        android:id="@+id/status"
        style="@style/textObjectInfo"
        android:layout_toRightOf="@id/labelStatus"
        android:text="@string/status" />
</RelativeLayout>
</RelativeLayout>

现在,我正在使用一个自定义类,它从IdentifyResultSpinnerAdapter 扩展而来。目的是使用 View-content 进行回调(Identify 正在使用异步任务处理)。下面是我用来返回 View 对象的方法;

        RelativeLayout layout = (RelativeLayout) mainThread.findViewById(R.id.objectInfo);
    // set textview
    TextView txt;

    // set naam
    txt = (TextView)layout.findViewById(R.id.status);
    if(curResult.getAttributes().containsKey("status")){
        txt.setText(curResult.getAttributes().get("status").toString());    
    }
    else txt.setText("N/A");
    // **1

    layout.invalidate();
    layout.setVisibility(View.VISIBLE);
    return layout;

(**1如前所述,只显示一个变化,其他3个字段处理方式相同)然后在主活动类中;

/**
* this method handles the result after tap event and displays it on the map
* @param p the point where the tap event got recorded
* @param v the view result
* @see IdentifyTaskManager
*/
public void handleResults(Point p, ViewGroup v) {
    mMapView.getCallout().show(p, v);
}

下图显示了上述代码的结果。(嗯,你需要 10 个代表点来显示图像,这是 URL

如您所见,RelativeLayout 窗口(橙色)显示为停留在该位置的静态布局,无论我在地图上点击哪个对象。弹出窗口显示为空,因为那里没有布局。

有没有人知道问题是什么,或者什么会导致这种影响?谢谢你。

4

1 回答 1

0

我找到了解决方案。我决定深入研究 View / RelativeLayout 文档并遇到 LayoutInflater 类。感谢这两个链接,stackovervlow 上的这个问题这个博客我可以找到一个解决方案。

首先,我将 xml 布局移动到一个单独的文件中,名为 popupwindow.xml

其次,使用 LayoutInflater 类(变量 mainThread 是对从 Activity 扩展的主类的引用 - 需要获取 Context 信息);

View view = null;
try {
    LayoutInflater inflater = LayoutInflater.from(mainThread.getBaseContext());
    view = inflater.inflate(R.layout.popupwindow, null); // get info from popupwindow.xml
}
catch (Exception e) {
    Log.d(null, "159 - error after inflater : " + e.getMessage());
}
// return null if inflater fails;
if (view == null) return null;

// set textview
TextView txt;

// set status
txt = (TextView)layout.findViewById(R.id.status);
if(curResult.getAttributes().containsKey("status")){
    txt.setText(curResult.getAttributes().get("status").toString());    
}
// return view
return view;

我很高兴:-)

于 2013-05-23T19:27:44.363 回答