我有Android的默认"滚动活动" 。不同之处在于我在SupportMapFragment
添加了CollapsingToolbarLayout
。以下是xml:
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="16dp"
app:expandedTitleMarginBottom="16dp">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.abc.def.ui.activities.tasks.TaskDetailActivity"
tools:showIn="@layout/activity_task_detail"
app:layout_collapseMode="parallax">
</fragment>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
地图显示正常但当我点击标记时,地图工具栏按钮隐藏在FloatingActionButton
后面。
在给定here的情况下,我尝试将按钮移动到其他角落,但他们停止响应点击,即我没有重定向到地图应用。
然后我尝试扩展SupportMapFragment
,将包含两个按钮的自定义视图添加到片段中。并指定了单击侦听器按钮。 同样,对点击无响应。以下是片段中的代码,其中包含SupportMapFragment
。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FrameLayout wrapper = new FrameLayout(inflater.getContext());
View mapView = super.onCreateView(inflater, container, savedInstanceState);
wrapper.addView(mapView);
mCustomView = inflater.inflate(R.layout.toolbar_map, wrapper, false);
wrapper.addView(mCustomView);
return wrapper;
}
@Override
public void onActivityCreated(Bundle bundle) {
super.onActivityCreated(bundle);
if(mCustomView != null){
View clickable1 = mCustomView.findViewById(R.id.toolbar_map_btn_1);
View clickable2 = mCustomView.findViewById(R.id.toolbar_map_btn_2);
clickable1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mLatLng != null){
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?daddr="+mLatLng.latitude+", "+mLatLng.longitude));
startActivity(intent);
}
}
});
clickable2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mLatLng != null){
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?q=loc:"+mLatLng.latitude+", "+mLatLng.longitude));
startActivity(intent);
}
}
});
}
}
然后我尝试将两个按钮添加到CollapsingToolbarLayout
。这次我引用了按钮并在Activity本身中分配了click事件。再次,没有成功。
每次,我都可以在地图上显示按钮,无论我想要什么,但点击不起作用,除非在第一种情况下,它们部分隐藏在FAB后面。
请帮忙。