【问题标题】:My ViewLabel under Nutiteq doesn't work fineNutiteq 下的我的 ViewLabel 无法正常工作
【发布时间】:2014-07-10 16:35:33
【问题描述】:

我可以在 Nutiteq 中为我的 ViewLabel 填充视图,但我无法在此布局的文本视图中设置正确的文本。

我的代码如下

    //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);

    //In order to get a dynamic "redimensionable" Ballon aka ViewLabel
    labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                      MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());

    //labelView.measure(400, 400);
    //labelView.layout(100, 100, 400, 400);

    Log.info("drawField:: Nach Label fieldLabel = new ViewLabel... ");

    LinearLayout lLayout = (LinearLayout)labelView.findViewById(R.id.layout1);
    lLayout.setBackgroundColor(Color.RED);
    TextView farmNameTV  = (TextView)labelView.findViewById(R.id.farmName);
    TextView areaTV      = (TextView)labelView.findViewById(R.id.area);
    TextView statusTV    = (TextView)labelView.findViewById(R.id.status);

    farmNameTV.setTextColor(Color.BLACK);
    farmNameTV.setText("Farm CacoCaCoca");


    areaTV.setTextColor(Color.BLACK);
    String areaString = "12.34"
    areaTV.setText("Area "+areaString);

    statusTV.setTextColor(Color.BLACK);
    String statusString = "Status:::qwertzuiopasdfghjklyxcvbnm";
    statusTV.setText(statusString); 

*你看到的红色是我的膨胀视图。

R.layout.popup_field 看起来像这样

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

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

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

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

字符串在哪里

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Nutiteq3D</string>
<string name="area">Area</string>
<string name="status">Status</string>
<string name="farmName">Farm Name</string>
</resources>

有人已经完成了这项任务吗?谁能帮我找出我的错误?

使用 Google Api 的 MapView 很容易,但我使用 Nutiteq 和纯活动来开发它,所以,没有片段和膨胀,我们通常需要一个 ViewGroup,G-Api 下的这个 ViewGroup 将是 MapView,所以继承自 ViewGroup 但在 Nutiteq不是这样的,Nutiteq 的 MapView 继承了 android.view 并且我无法转换,我可以在 inflate 的调用中将 null 分配为 ViewGroup,如您所见。

所以,各位,我非常感谢您的帮助。

亲切的问候

【问题讨论】:

    标签: android-linearlayout android-custom-view layout-inflater nutiteq


    【解决方案1】:

    解决了! 它与ViewLabel 无关,但与正常的Android.View 无关,我想在声明我的可调整大小的View 后将Text 分配给TextView,因此它不能正常工作。

    所以解决方案是写上面的所有tv.setText labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多