2013-07-01 45 views
2

我搜索一些滑動示例,如何做從右到左滑動菜單

但我仍然無法找到從右到左的滑動示例。

可以請從右邊滑動菜單中的任何一個給定樣本項目向左

+0

這是已經在堆棧看下面的鏈接http://stackoverflow.com/questions/11465774/android-how-to-make-slide-menu-like-facebook-spotify-and-google – Sri

+0

請參閱此鏈接 - http://stackoverflow.com/questions/13546148/advice-implementation-of-slidingmenu-on-android-j-feinstein/13546224#13546224 – FraZer

回答

3
package com.slidingmenu.example; 

import android.os.Bundle; 
import android.view.KeyEvent; 
import android.view.View; 
import android.view.ViewGroup; 

import com.slidingmenu.example.fragments.ColorFragment; 
import com.slidingmenu.lib.SlidingMenu; 
import com.slidingmenu.lib.SlidingMenu.OnClosedListener; 
import com.slidingmenu.lib.SlidingMenu.OnOpenedListener; 


public class LeftAndRightActivity extends BaseActivity { 

public LeftAndRightActivity() { 
super(R.string.left_and_right); 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT); 
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); 

setContentView(R.layout.content_frame); 
getSupportFragmentManager() 
.beginTransaction() 
.replace(R.id.content_frame, new SampleListFragment()) 
.commit(); 

getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_two); 
getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright); 
getSupportFragmentManager() 
.beginTransaction() 
.replace(R.id.menu_frame_two, new SampleListFragment()) 
.commit(); 
} 

} 

確保獲得庫的乾淨和更新的副本,以及。以防萬一。

+0

數據庫錯誤爲自己的鏈接。請檢查出來 –

+0

這頁由於某些數據庫問題而暫時不可用。 –

+0

go for this http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/ –

3

幻燈片菜單可以通過動畫類

//Declare inside activity 

     private LinearLayout slidingPanel; 
     private boolean isExpanded; 
     private DisplayMetrics metrics; 
     //private ListView listView; 
     private RelativeLayout headerPanel,menuPanel; 

     private int panelWidth; 
     private ImageView menuViewButton; 

     FrameLayout.LayoutParams menuPanelParameters; 
     FrameLayout.LayoutParams slidingPanelParameters; 
     LinearLayout.LayoutParams headerPanelParameters ; 
     LinearLayout.LayoutParams listViewParameters; 

    //Initialize inside oncreate 
       metrics = new DisplayMetrics(); 
       getWindowManager().getDefaultDisplay().getMetrics(metrics); 
       panelWidth = (int) ((metrics.widthPixels)*0.45); 

       headerPanel = (RelativeLayout) findViewById(R.id.header); 
       headerPanelParameters = (LinearLayout.LayoutParams) headerPanel.getLayoutParams(); 
       headerPanelParameters.width = metrics.widthPixels; 
       headerPanel.setLayoutParams(headerPanelParameters); 

       menuPanel = (RelativeLayout) findViewById(R.id.menuPanel); 
       menuPanelParameters = (FrameLayout.LayoutParams) menuPanel.getLayoutParams(); 
       menuPanelParameters.width = panelWidth; 
       menuPanel.setLayoutParams(menuPanelParameters); 

       slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel); 
       slidingPanelParameters = (FrameLayout.LayoutParams)     slidingPanel.getLayoutParams(); 
       slidingPanelParameters.width = metrics.widthPixels; 
       slidingPanel.setLayoutParams(slidingPanelParameters); 




       //Slide the Panel 
       menuViewButton = (ImageView) findViewById(R.id.menuViewButton); 
       menuViewButton.setOnClickListener(new OnClickListener() { 
        public void onClick(View v) { 
         if(!isExpanded){ 
        isExpanded = true;           

        //Expand 
        new ExpandAnimation(slidingPanel, panelWidth, 
          Animation.RELATIVE_TO_SELF, 0.0f, 
          Animation.RELATIVE_TO_SELF, 0.45f, 0, 0.0f, 0, 0.0f); 
        //Toast.makeText(getApplicationContext(), "expand", 0).show(); 


         }else{ 
          isExpanded = false; 

          //Collapse 
          new CollapseAnimation(slidingPanel,panelWidth, 
          TranslateAnimation.RELATIVE_TO_SELF, 0.45f, 
          TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f, 0, 0.0f); 

        //Toast.makeText(getApplicationContext(), "Collapse", 0).show(); 

         }    
        } 
       }); 


//collapse animation class 

    public class CollapseAnimation extends TranslateAnimation implements TranslateAnimation.AnimationListener{ 

     private LinearLayout slidingLayout; 
     int panelWidth; 
     public CollapseAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType, 
       float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) { 

      super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue); 

      //Initialize 
      slidingLayout = layout; 
      panelWidth = width; 
      setDuration(400); 
      setFillAfter(false); 
      setInterpolator(new AccelerateDecelerateInterpolator()); 
      setAnimationListener(this); 

      //Clear left and right margins 
      LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams(); 
      params.rightMargin = 0; 
      params.leftMargin = 0; 
      slidingLayout.setLayoutParams(params); 
      slidingLayout.requestLayout();  
      slidingLayout.startAnimation(this); 
      //slidingLayout.setBackgroundColor(); 
      //slidingLayout.setBackgroundColor(R.string.white); 

     } 
     @Override 
     public void onAnimationEnd(Animation arg0) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onAnimationRepeat(Animation arg0) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onAnimationStart(Animation arg0) { 
      // TODO Auto-generated method stub 

     } 

    } 


//expande animation class 

    public class ExpandAnimation extends TranslateAnimation implements Animation.AnimationListener{ 
     private LinearLayout slidingLayout; 
     int panelWidth; 
     public ExpandAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType, 
       float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) { 

      super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue); 

      //Initialize 
      slidingLayout = layout; 
      panelWidth = width; 
      setDuration(400); 
      setFillAfter(false); 
      setInterpolator(new AccelerateDecelerateInterpolator()); 
      setAnimationListener(this); 
      slidingLayout.startAnimation(this); 
      //slidingLayout.setBackgroundColor(panelWidth); 
     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      // TODO Auto-generated method stub 
      //Create margin and align left 
        LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams(); 
        params.leftMargin = panelWidth; 
        params.gravity = Gravity.LEFT;  
        slidingLayout.clearAnimation(); 
        slidingLayout.setLayoutParams(params); 
        slidingLayout.requestLayout(); 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void onAnimationStart(Animation animation) { 
      // TODO Auto-generated method stub 

     } 

    } 

///here is the xml 

    <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <!-- Menu Panel --> 

      <RelativeLayout 
       android:id="@+id/menuPanel" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:background="@drawable/gray_bg" 
       android:gravity="right" 
       android:orientation="vertical" > 

       <TextView 
        android:id="@+id/menu_title_1" 
        android:layout_width="fill_parent" 
        android:layout_height="50dp" 
        android:layout_alignParentTop="true" 
        android:layout_marginLeft="0dp" 
        android:background="#353535" 
        android:gravity="center_vertical" 
        android:paddingLeft="15dp" 
        android:text="@string/menu_title" 
        android:textColor="@android:color/white" > 
       </TextView> 

       <View 
        android:id="@+id/menu_item_divider_1" 
        android:layout_width="fill_parent" 
        android:layout_height="0.5dp" 
        android:layout_below="@+id/menu_title_1" 
        android:layout_marginLeft="0dp" 
        android:layout_marginRight="0dp" 
        android:background="#b5b5b5" /> 

       <TextView 
        android:id="@+id/menu_item_1" 
        android:layout_width="fill_parent" 
        android:layout_height="50dp" 
        android:layout_below="@+id/menu_item_divider_1" 
        android:layout_marginLeft="15dp" 
        android:gravity="center_vertical" 
        android:text="@string/korean" > 
       </TextView> 

       <View 
        android:id="@+id/menu_item_divider_2" 
        android:layout_width="fill_parent" 
        android:layout_height="0.5dp" 
        android:layout_below="@+id/menu_item_1" 
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="5dp" 
        android:background="#b5b5b5" /> 

       <TextView 
        android:id="@+id/menu_item_2" 
        android:layout_width="fill_parent" 
        android:layout_height="50dp" 
        android:layout_below="@+id/menu_item_divider_2" 
        android:layout_marginLeft="15dp" 
        android:gravity="center_vertical" 
        android:text="@string/english" 
        > 
       </TextView> 



      <!-- Sliding Panel --> 

      <LinearLayout 
       android:id="@+id/slidingPanel" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@android:color/white" 
       android:gravity="left" 
       android:orientation="vertical" > 

       <View 
        android:id="@+id/dividerHeaderBottom" 
        android:layout_width="fill_parent" 
        android:layout_height="1dp" 
        android:background="#414141" /> 

       <RelativeLayout 
        android:id="@+id/header" 
        android:layout_width="match_parent" 
        android:layout_height="45dp" 
        android:background="@color/whitec" > 



        <Button 
         android:id="@+id/buttonback" 
         android:layout_width="40dp" 
         android:layout_height="40dp" 
         android:layout_alignBottom="@+id/buttonperson" 
         android:layout_alignParentTop="true" 
         android:layout_marginRight="14dp" 
         android:layout_toLeftOf="@+id/buttonperson" 
         android:background="@drawable/back" /> 



    <ImageView 
       android:id="@+id/menuViewButton" 
       android:layout_width="40dp" 
       android:layout_height="40dp" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="27dp" 
       android:layout_toRightOf="@+id/buttonyummy" 
       android:clickable="true" 
       android:contentDescription="@string/description" 
       android:src="@drawable/lin" 
       android:visibility="visible" /> 

       </RelativeLayout> 
      </LinearLayout> 
     </FrameLayout> 
-1

使用this庫來完成。它有右至左滑動抽屜也..

在活動的 onCreate()或任何適合你可以使用

下面的實現..

rightDrawer = new DrawerBuilder() 
    .withActivity(this) 
    .withDisplayBelowStatusBar(true) 
    .withSavedInstance(savedInstanceState) 
    .withDrawerGravity(Gravity.END).append(leftDrawer); // or use build() instead of append() 

這將增加從右向左滑動抽屜...

+0

雖然這可能在理論上回答這個問題,[這將是最好的](/元。 stackoverflow.com/q/8259)將答案的重要部分包括在內,並提供參考鏈接。 –