nutiteq: Button resp. clickable Views not working in Custom ViewLabel

早过忘川 提交于 2020-01-14 17:52:03

问题


I am able to make a fully customized ViewLabel in Android nutiteq, defining layout design and sizes. However, clickable Views are not working as expected. First I tried to make the whole label clickable by defining the root layout as clickable, but this didn't work. Adding a Button too does not work. How can this problem be solved?

MapPos markerLoc = rasterLayer.getProjection().fromWgs84(lng, lat);
Marker marker;

CustomPOILayout layout = new CustomPOILayout(this);
layout.setTitle((poi.title.trim().length() == 0)? "kein Titel" : poi.title);
layout.setDescription((poi.desc.trim().length() == 0)? "keine Beschreibung" : poi.desc);
layout.setDateAndAuthor(COSAHelper.convertTimestamp(poi.resCreated) + "\nvon: " + poi.author);
layout.setImages(poi.byteStrings);

layout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                        MeasureSpec.makeMeasureSpec(0,  MeasureSpec.UNSPECIFIED)); 
layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

Label label = new ViewLabel("", layout, 
                            new Handler(), 
                            LabelStyle.builder()
                                .setAlpha(1.0f)
                                .setBorderRadius(0)
                                .setBorderColor(Color.GRAY)
                                .setBorderWidth(5)
                                .build()
                            );


marker = new Marker(markerLoc, label, markerStyle3, markerLayer);
markerLayer.add(marker);

the xml layout

<TextView 
    android:id="@+id/label_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:textStyle="bold"
    />

<View 
    android:layout_width="match_parent"
    android:layout_height="1dip"
    android:background="@color/abc_search_url_text_normal"
    />

<TextView 
    android:id="@+id/label_date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="11sp"
    />

<TextView 
    android:id="@+id/label_description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    />

<View 
    android:layout_width="match_parent"
    android:layout_height="1dip"
    android:background="@color/abc_search_url_text_normal"
    />

<LinearLayout 
    android:id="@+id/label_container1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <ImageView 
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_margin="5dip"
        android:minHeight="25dip"
        />

    <ImageView 
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_margin="5dip"
        android:minHeight="25dip"
        />
</LinearLayout>

<LinearLayout 
    android:id="@+id/label_container2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <ImageView 
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_margin="5dip"
        android:minHeight="25dip"
        />

    <ImageView 
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_margin="5dip"
        android:minHeight="25dip"
        />
</LinearLayout>

<TextView 
    android:id="@+id/label_text_images"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    />

<View 
    android:layout_width="match_parent"
    android:layout_height="1dip"
    android:background="@color/abc_search_url_text_normal"
    />

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="zeige Ressource"
    android:gravity="center"
    android:onClick="onClickTest"
    android:layout_gravity="center"
    android:textSize="14sp"/>


回答1:


If I understand correctly, you want all clicks to be forwarded to the view inside the label? ViewLabel has method for this: setTouchHandlingMode. Simply call viewLabel.setTouchHandlingMode(true).



来源:https://stackoverflow.com/questions/28629683/nutiteq-button-resp-clickable-views-not-working-in-custom-viewlabel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!