【问题标题】:Nutiteq ViewLabel doesn't appearNutiteq ViewLabel 不出现
【发布时间】:2014-06-13 11:05:28
【问题描述】:

谁能告诉我我做错了什么?

我可以在 Nutiteq 的 GeometryLayer 上构建和显示多边形,但是当我尝试创建自定义标签时,又名 ViewLabel 不显示,DefaultLabel 工作正常。

我有一个普通的 XML 布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/farmName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/farmName"/>

    <TextView
        android:id="@+id/area"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"       
        android:text="@string/area"/>

</LinearLayout>

还有我的代码

//Setting Popup Label if we click the area
LayoutInflater inflater =(LayoutInflater)this.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);      
View labelView = inflater.inflate(R.layout.popup_field, null);


TextView farmNameTV = (TextView)labelView.findViewById(R.id.farmName);
TextView areaTV = (TextView)labelView.findViewById(R.id.area);

farmNameTV.setTextColor(Color.BLACK);
farmNameTV.setTextSize(13*scale);
farmNameTV.setText("Farm Name: "+name);

GeometricUtils geomUtils = new GeometricUtils();
double area = geomUtils.computeArea(coordinates);


areaTV.setTextColor(Color.BLACK);
areaTV.setTextSize(13*scale);        
areaTV.setText("Area :"+String.valueOf(area));


labelView.layout(0, 0, 400, 300);




LabelStyle labelStyle = LabelStyle.builder().setBackgroundColor(Color.WHITE).
                               setEdgePadding((int) (12 * scale)).
                               setLinePadding((int) (6 * scale)).
                               setTitleFont(Typeface.create("Arial", Typeface.BOLD),
                                            16 * scale).
                               setTitleColor(Color.BLACK).
                               setTitleAlign(Align.CENTER).
                               setDescriptionFont(Typeface.create("Arial",  
                                                  Typeface.NORMAL),13 * scale).
                               setDescriptionColor(Color.BLACK).
                               setDescriptionAlign(Align.CENTER).
                               build();




Label fieldLabel = new ViewLabel(fieldname, labelView, new Handler(), labelStyle);


// Without holes!
Polygon pol = new Polygon(outerPoses, null, fieldLabel, polygonStyleSet, null);
geomLayer.add(pol);

我尝试在 XML 文件中设置 View 的属性,如您所见,也以编程方式设置,但没有成功。

Capture of my issue

我什至尝试为我的带有多边形的图层编写 MapListener 的扩展程序,并从中获取数据

public void onVectorElementClicked(VectorElement vectorElement, double x, double y,    
                                   boolean longClick) {
    if (vectorElement.getLabel() != null) {   
        ViewLabel label = vectorElement.getLabel();
        ...
        And here we can get all of data of label
        ...
    }
}

提前致谢!

【问题讨论】:

    标签: label polygon android-custom-view nutiteq


    【解决方案1】:

    问题可能是您没有测量您的布局,请参阅https://github.com/nutiteq/hellomap3d/wiki/Use-View-for-Label。你应该在 webView.layout() 之前添加

    webView.measure(400, 300); 
    

    【讨论】:

    • 嗨 Jaak,谢谢,就是这样!我还不能投票,但当我可以投票时,我会投赞成票。亲切的问候!
    • @bavarol 但是,您可以使用accept the answer,这将为你们俩提供reputation
    • 抱歉,我想,Accept 与支持他有关,我还不能支持。谢谢
    • 我不明白为什么我得到 -3 只是因为提出问题。
    猜你喜欢
    • 1970-01-01
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多