0
我有一個MapView,我希望有一個動畫菜單的選項,從屏幕左側滑入,並在用戶單擊頂部導航欄上的圖標時覆蓋一個MapView。MapView頂部的動畫菜單按鈕
希望的行爲是: 1.用戶單擊頂部導航欄上的圖標 2.菜單從左側滑入,顯示具有不同選項的按鈕。 3.如果用戶選擇取消或返回到地圖視圖,則菜單向右滑出並消失。
什麼是在MapView上實現這種行爲的最佳方法?
我有一個MapView,我希望有一個動畫菜單的選項,從屏幕左側滑入,並在用戶單擊頂部導航欄上的圖標時覆蓋一個MapView。MapView頂部的動畫菜單按鈕
希望的行爲是: 1.用戶單擊頂部導航欄上的圖標 2.菜單從左側滑入,顯示具有不同選項的按鈕。 3.如果用戶選擇取消或返回到地圖視圖,則菜單向右滑出並消失。
什麼是在MapView上實現這種行爲的最佳方法?
首先,你需要添加的按鈕在同一個XML的佈局,你有你的MapView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<view
android:id="@+id/mv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.maps.MapView"
android:apiKey="your key"
android:clickable="true" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_layout_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingRight="5dp" >
<Button
android:id="@+id/button_overlay_show_zoom_all"
android:layout_width="64dp"
android:layout_height="64dp"
android:paddingBottom="10dp" />
<Button
android:id="@+id/button_overlay_previous"
android:layout_width="64dp"
android:layout_height="64dp"
android:paddingBottom="10dp" />
<Button
android:id="@+id/button_overlay_next"
android:layout_width="64dp"
android:layout_height="64dp"
android:paddingBottom="10dp" />
</LinearLayout>
</RelativeLayout>
然後,你需要初始化按鈕(我假設你知道這部分)
然後你定義動畫的方法:
//Buttons Fadein/Fadeout-------------------------------------------------------------------------------
private void buttonFadeOut() {
linear_layout_buttons.startAnimation(AnimationUtils.loadAnimation(MyMapActivity.this, android.R.anim.slide_out_right));
linear_layout_buttons.setVisibility(View.GONE);
}
private void buttonFadeIn() {
if(linear_layout_buttons.getVisibility() == View.GONE){
linear_layout_buttons.startAnimation(AnimationUtils.loadAnimation(MyMapActivity.this, android.R.anim.slide_out_left));
linear_layout_buttons.setVisibility(View.VISIBLE);
}
最後,您只需在需要的地方調用buttonFadeIn()和ButtonFadeOut()。
祝你好運。