-
-
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
commented
Dec 9, 2015
main_activity.xml
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoShadowHeight="0dp"
sothree:umanoPanelHeight="300dp"
sothree:umanoOverlay="true"
sothree:umanoFadeColor="@android:color/transparent"
sothree:umanoDragView="@+id/dragView">
<fragment
android:id="@+id/map"
android:windowSoftInputMode="adjustResize"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
<include layout="@layout/sliding_fragment_layout"
android:background="#ffffff"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView"/>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
sliding_fragment_layout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:id="@+id/verified"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="60dp"
android:clickable="true"
android:focusable="false"
android:paddingLeft="10dp"
android:background="#FFFF"
android:paddingRight="10dp"
android:paddingTop="10dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<!--android:descendantFocusability="beforeDescendants"-->
<!--android:focusableInTouchMode="true"-->
<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"/>
</TableLayout>
Just watched your video. Padding setted correctly. You can see it by Google mark being moved on top of the panel. So it looks like the problem is in animation of zoom to the marker on marker tap. Like I said during animation CURRENT map center stays untouched and in your case marker is not in center of the map when tap performed. What you can do is:
- On tap save the marker position in the local variable.
- In onPanelSlide callback move camera not to the current map center like I did but to the position you saved.
Okay two things : firstly , i think i passed the correct padding and even after removing animation it works with same issue . And Secondly , If applying an answer gives me more issue then why would i apply it . Hence , it is in scope .
okay i try the above solution . And see if it resolving my issue . Anyways thanx alot again
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.
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 ?
Well , yes suggestion worked . And marked tick on stack as well . 👍
And while using answer i learnt many things . Really . this not only resolved my issue but help exploring and learning stuff .
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.
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 ?
Actually slidingUpPanel is collapsed on start. You defenitly do something wrong.
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