我能够在Android nutiteq中制作完全自定义的ViewLabel,定义布局设计和尺寸。但是,可点击的视图无法按预期工作。首先,我尝试通过将根布局定义为可点击来使整个标签可点击,但这并不起作用。添加按钮也不起作用。如何解决这个问题?
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);
xml布局
<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"/>
答案 0 :(得分:1)
如果我理解正确,您希望将所有点击转发到标签内的视图吗? ViewLabel 有以下方法: setTouchHandlingMode 。只需拨打 viewLabel.setTouchHandlingMode(true)。