我已经搜索了几个小时,但我仍然无法找到关于如何实现像谷歌地图这样响应触摸的操作栏的答案?即使用户滚动操作栏顶部,地图仍会滚动。请拜托。
这是xml文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
tools:context=".MainActivity"
android:id="@+id/parentLayout">
<com.manuelpeinado.fadingactionbar.view.ObservableScrollView
android:id="@+id/scrollview"
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="560dp"
android:fillViewport="false"
android:layout_above="@+id/disclaimer_container">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="175dp"
android:id="@+id/ulo">
<fragment
android:id="@+id/facility_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:adjustViewBounds="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/facility_map_dummy"
android:focusableInTouchMode="true"
android:background="@drawable/dummy"
android:alpha="0.3" />
</RelativeLayout>
<include
android:id="@+id/content"
layout="@layout/activity_establishment_details">
</include>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"></RelativeLayout>
</LinearLayout>
</com.manuelpeinado.fadingactionbar.view.ObservableScrollView>
<include
android:id="@+id/tool_bar_facility"
layout="@layout/tool_bar">
</include>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:id="@+id/disclaimer_container"
android:focusableInTouchMode="false"
android:background="@android:color/background_light">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:drawable/divider_horizontal_bright"
android:id="@+id/line"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To ensure ease and convenience of your medical availment, please proceed to the physician coordinator’s clinic, Industrial Department, or the HMO Office first. Your physician coordinator will refer you to the appropriate specialist."
android:id="@+id/textView7"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:textSize="12sp" />
</LinearLayout>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
sothree:umanoPanelHeight="180dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoOverlay="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
<RelativeLayout
android:id="@+id/map_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<fragment
android:id="@+id/doctor_map2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dummy"
android:background="@drawable/dummy"
android:alpha="0.7" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:id="@+id/up"
android:layout_height="wrap_content"
app:backgroundTint="@color/action_green"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_up" />
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</android.support.design.widget.CoordinatorLayout>
这是活动
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facility_details);
initLayout();
context = this;
mToolbar = (Toolbar) findViewById(R.id.tool_bar_facility);
mActionBarBackgroundDrawable = mToolbar.getBackground();
dc = new DataCollection(FacilityDetailActivity.this);
previousDrawable = mToolbar.getBackground();
setSupportActionBar(mToolbar);
mToolbar.setPadding(0, Globals.getStatusBarHeight(this), 0, 0);
// create our manager instance after the content view is set
SystemBarTintManager tintManager = new SystemBarTintManager(this);
// enable status bar tint
tintManager.setStatusBarTintEnabled(true);
// enable navigation bar tint
tintManager.setNavigationBarTintEnabled(true);
// set the transparent color of the status bar, 20% darker
tintManager.setTintColor(Color.parseColor("#20000000"));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle(" ");
mStatusBarManager = new SystemBarTintManager(this);
mStatusBarManager.setStatusBarTintEnabled(true);
mInitialStatusBarColor = ContextCompat.getColor(this, R.color.main_color_dark);
mFinalStatusBarColor = ContextCompat.getColor(FacilityDetailActivity.this, R.color.main_color_dark);
report_error = (TextView) findViewById(R.id.report_error);
coordinatorLayout = (CoordinatorLayout) findViewById(R.id.parentLayout);
mHeader = findViewById(R.id.facility_map);
report_error.setVisibility(Globals.ACTIVATE_REPORT_ERROR ? View.VISIBLE : View.GONE);
ObservableScrollable scrollView = (ObservableScrollable) findViewById(R.id.scrollview);
scrollView.setOnScrollChangedCallback(this);
onScroll(-1, 0);
initValues();
setUpMapIfNeeded();
slidingPane = (SlidingUpPanelLayout)findViewById(R.id.sliding_layout);
slidingPane.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
fab =(FloatingActionButton)findViewById(R.id.up);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
slidingPane.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
}
});
report_error.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(FacilityDetailActivity.this, ReportErrorActivity.class);
startActivity(intent);
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
float elevation = 4 * getResources().getDisplayMetrics().density;
mToolbar.setElevation(elevation);
}
}
这是设置地图的方法
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.facility_map))
.getMap();
mMap2 = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.doctor_map2))
.getMap();
if (mMap != null) {
setUpMap();
setUpMap2();
}
}
}
private void setUpMap() {
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
slidingPane.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}
});
LatLng coordinates = new LatLng(facility.getLatitude(),facility.getLongitude());
CameraUpdate center = CameraUpdateFactory.newLatLng(coordinates);
CameraUpdate zoom = CameraUpdateFactory.zoomTo(13);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
mMap.addMarker(new MarkerOptions()
.position(coordinates)
.title(facility.getName())
.snippet(facility.getAddress() + ", " + facility.getCityName() + ", "
+ facility.getProvinceName())
.icon(CustomBitmapPin.getCorrespondingMapPinForFacility(this, facility))
.anchor(0.5f, 0.5f));
final ScrollView mainLayout = (ScrollView)findViewById(R.id.scrollview);
final ImageView dummy = (ImageView)findViewById(R.id.facility_map_dummy);
dummy.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
mainLayout.requestDisallowInterceptTouchEvent(true);
// Disable touch on transparent view
return false;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
mainLayout.requestDisallowInterceptTouchEvent(false);
return true;
case MotionEvent.ACTION_MOVE:
mainLayout.requestDisallowInterceptTouchEvent(true);
return false;
default:
return true;
}
}
});
}
我已经尝试了这个但它仍然无效
mToolbar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
mToolbar.requestDisallowInterceptTouchEvent(true);
return false;
case MotionEvent.ACTION_UP:
mToolbar.requestDisallowInterceptTouchEvent(true);
return false;
case MotionEvent.ACTION_MOVE:
mToolbar.requestDisallowInterceptTouchEvent(true);
return false;
default:
return true;
}
}
});