2012-07-04 43 views
0

在我的Android應用程序中,當我單擊屏幕上的一個按鈕時,我想要一個側面板。我不知道如何做到這一點。單擊某個按鈕時的Android側面板

你能幫忙嗎?

+0

http://stackoverflow.com/questions/10480049/how-to-make-a-sidebar-menu/10480723#10480723 – blessenm

回答

0

使用slidingDrawer找到下面的示例代碼。 main.xml中

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/LinearLayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/icon_image" 
     android:gravity="bottom" 
     android:orientation="vertical" > 

     <ImageView 
       android:id="@+id/imageVW" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:background="@drawable/vincent" > 
      </ImageView> 
     <SlidingDrawer 
      android:id="@+id/SlidingDrawer" 
      android:layout_width="wrap_content" 
      android:layout_height="250dip" 
      android:content="@+id/contentLayout" 
      android:handle="@+id/slideHandleButton" 
      android:padding="10dip" > 

      <Button 
       android:id="@+id/slideHandleButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/closearrow" > 
      </Button> 

      <LinearLayout 
       android:id="@+id/contentLayout" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center|top" 
       android:orientation="vertical" 
       android:background="#ff00ff" 
       android:padding="10dip" > 

       <Button 
        android:id="@+id/Button01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Content" > 
       </Button> 

       <Button 
        android:id="@+id/Button02" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:text="Content" > 

       </Button> 

       <Button 
        android:id="@+id/Button03" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Content" > 
       </Button> 
      </LinearLayout> 
     </SlidingDrawer> 

    </LinearLayout> 

slidingDrawerExample.java

import android.app.Activity; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.view.View.OnClickListener; 
    import android.widget.Button; 
    import android.widget.SlidingDrawer; 
    import android.widget.SlidingDrawer.OnDrawerCloseListener; 
    import android.widget.SlidingDrawer.OnDrawerOpenListener; 
    import android.widget.Toast; 

    public class slidingDrawerExample extends Activity { 

     Button slideHandleButton; 
     SlidingDrawer slidingDrawer; 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      setContentView(R.layout.main); 
      slideHandleButton = (Button) findViewById(R.id.slideHandleButton); 
      slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer); 
      Button b = (Button) findViewById(R.id.Button01); 
      b.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 
        Toast.makeText(getBaseContext(), "This is button 1", 9).show(); 
       } 
      }); 

      slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() { 

       public void onDrawerOpened() { 
        slideHandleButton.setBackgroundResource(R.drawable.openarrow); 
       } 
      }); 

      slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() { 

       public void onDrawerClosed() { 
        slideHandleButton.setBackgroundResource(R.drawable.closearrow); 
       } 
      }); 

     } 

    } 
+0

謝謝非常! :) 我會馬上試試! :) – Saku

+0

非常感謝和這個作品!但是我希望側面板從窗口右側水平顯示。改變方向不會成功。你能幫助我嗎? : - /對不起,如果即時通訊造成太多的麻煩: - / – Saku

相關問題