Skip to content

Instantly share code, notes, and snippets.

@Lingviston
Created December 8, 2015 12:22
Show Gist options
  • Save Lingviston/1d97660f7a5888ca0f76 to your computer and use it in GitHub Desktop.
Save Lingviston/1d97660f7a5888ca0f76 to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener{
private SupportMapFragment mMapFragment;
private SlidingUpPanelLayout mSlidingUpPanelLayout;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.slidingUpLayout);
mSlidingUpPanelLayout.setPanelSlideListener(this);
mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng latLng = new LatLng(53.9, 27.5666667);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 17);
MarkerOptions options = new MarkerOptions().position(latLng);
googleMap.addMarker(options);
googleMap.moveCamera(cameraUpdate);
}
});
}
@Override
public void onPanelSlide(View panel, final float slideOffset) {
final int panelHeight = findViewById(R.id.panel).getHeight();
final int visiblePanelHeight = mSlidingUpPanelLayout.getPanelHeight();
mMapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
CameraPosition cameraPosition = googleMap.getCameraPosition();
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition);
googleMap.setPadding(0,0,0, (int) (visiblePanelHeight + (panelHeight - visiblePanelHeight) * slideOffset));
googleMap.moveCamera(cameraUpdate);
}
});
}
@Override
public void onPanelCollapsed(View panel) {
}
@Override
public void onPanelExpanded(View panel) {
}
@Override
public void onPanelAnchored(View panel) {
}
@Override
public void onPanelHidden(View panel) {
}
}
<?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
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/slidingUpLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
app:umanoOverlay="true"
app:umanoPanelHeight="40dp"
app:umanoShadowHeight="0dp"
app:umanoFadeColor="@android:color/transparent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:context=".MapsActivity"/>
<TextView
android:id="@+id/panel"
android:layout_width="match_parent"
android:layout_height="400dp"
android:text="Drag me"
android:background="@android:color/white"
android:gravity="center_horizontal|top"/>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
@shiprasinghal1
Copy link

okay i try the above solution . And see if it resolving my issue . Anyways thanx alot again

@Lingviston
Copy link
Author

Your original question was about map shaking. The problem was in that you don't understand how Android lays out views. It is solved by my answer as you confirmed. Problem with marker positioning is out of the scope cause it has nothing to do with map shaking.

In fact your current problem is in camera positioning on tap/slide up. It can be easily solved by you otherwise another question should be asked.

Let me know if suggested solution helps you.

@shiprasinghal1
Copy link

hey , thanks this worked . But can i ask you something that might be out of scope . When i am clicking on panel its Expanded and clicking again panel it going on panel height instead i want it to go Hidden . Can i do it ?

@shiprasinghal1
Copy link

Well , yes suggestion worked . And marked tick on stack as well . 👍

@shiprasinghal1
Copy link

And while using answer i learnt many things . Really . this not only resolved my issue but help exploring and learning stuff .

@Lingviston
Copy link
Author

Yes. By default tapping on dragview again sets state to COLLAPSED and it's ok in your case. You incorrectly understand the meaning of app:umanoPanelHeight attribute. It's height of the visible part in collapsed state. So you have to set it to 0dp and probably set TableLayout's height to 300 dp.

Or probably you can simply set state to HIDDEN on second tap but my opinion is that the first solution is more correct.

@shiprasinghal1
Copy link

I understood the meaning . But its really like troubling me with one another issue . Setting an panelHeight = 0 will raise a problem : on clicking marker no panel will show up . 2 . On making table layout to 300 dp : It will show panel on launch of app instead clicking marker and come up .

:( So thats the issue . Should i change in slidingUpPanel file instead changing to this ?

@Lingviston
Copy link
Author

Actually slidingUpPanel is collapsed on start. You defenitly do something wrong.

@shiprasinghal1
Copy link

I have done exactly what u said . I mean just changes in xml 's . Ahha.... mine is Hidden on start might be thats why . As i want it changed to collapsed on marker click only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment