当前位置:操作系统 > 安卓/Android >>

Android中SlidingDrawer介绍【安卓进化三十四】

  安卓中1.5后加入了SlidingDrawer【隐藏式抽屉】,设计原理在你的UI布局有限的情况下,放不下太多的控件的时候,可以考虑用这个隐藏式抽屉。用SlidingDrawer注意两点,一个是android:handle(委托要展开的图片加载Layout配置) 和android:content(要展开的Layout Content), 转载请标明出处:

 http://blog.csdn.net/wdaming1986/article/details/6898374

 

下面看程序截图:

                 程序开始界面:                                                           点击右边的箭头后出现的界面:

                          \                                 \                              

 

                            点击左边的箭头后出现的界面:

                                    \

在SlidingDrawerActivity工程下:

一、在com.cn.daming包下的SlidingDrawerMainActivity.java类中的代码:


<span style="font-size:16px;">package com.cn.daming; 
 
import android.app.Activity; 
import android.content.res.Configuration; 
import android.os.Bundle; 
import android.widget.GridView; 
import android.widget.ImageView; 
import android.widget.SlidingDrawer; 
 
public class SlidingDrawerMainActivity extends Activity { 
 
    private GridView gridView; 
    private SlidingDrawer slidingDrawer; 
    private ImageView imageView; 
    private int[] icons={ 
        R.drawable.title1, R.drawable.title2, 
        R.drawable.title3, R.drawable.title4, 
        R.drawable.title5, R.drawable.title6 
    }; 
     
    private String[] items={ 
        "Phone", "Message", "AddImage", "Music", "Telephone", "SMS"  
    }; 
     
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        gridView = (GridView)findViewById(R.id.mycontent); 
        slidingDrawer = (SlidingDrawer)findViewById(R.id.sliding_drawer); 
        imageView = (ImageView)findViewById(R.id.my_image); 
        MyGridViewAdapter adapter = new MyGridViewAdapter(this, items, icons); 
        gridView.setAdapter(adapter); 
        slidingDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() { 
             
            public void onDrawerOpened() { 
                imageView.setImageResource(R.drawable.right1); 
            } 
        }); 
        slidingDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() { 
             
            public void onDrawerClosed() { 
                imageView.setImageResource(R.drawable.left1); 
            } 
        }); 
    } 
 
    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
        super.onConfigurationChanged(newConfig); 
    } 
}</span> 
<span style="font-size:16px;">package com.cn.daming;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SlidingDrawer;

public class SlidingDrawerMainActivity extends Activity {

 private GridView gridView;
 private SlidingDrawer slidingDrawer;
 private ImageView imageView;
 private int[] icons={
  R.drawable.title1, R.drawable.title2,
  R.drawable.title3, R.drawable.title4,
  R.drawable.title5, R.drawable.title6
 };
 
 private String[] items={
  "Phone", "Message", "AddImage", "Music", "Telephone", "SMS" 
 };
 
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        gridView = (GridView)findViewById(R.id.mycontent);
        slidingDrawer = (SlidingDrawer)findViewById(R.id.sliding_drawer);
        imageView = (ImageView)findViewById(R.id.my_image);
        MyGridViewAdapter adapter = new MyGridViewAdapter(this, items, icons);
        gridView.setAdapter(adapter);
        slidingDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
   
   p

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,