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

android之抽屉布局应用

我们有时后希望在一个界面中显示另外一个布局,但是又要不需要占用太多布局空间,这个时候我们可以考虑用到抽屉布局,这个名词大家可以充分发挥能动想象,相信通过下面的介绍大家一定可以对这种方式有所了解.

好了,直接上一个简单的小项目.

1、首先我们建一个主activity

[java]
package com.jindegege.activity; 
 
import com.jindegege.service.MyAdapter; 
 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.GridView; 
import android.widget.ImageView; 
import android.widget.SlidingDrawer; 
public class SlidingdrawerActivity extends Activity { 
      
      private GridView gridview; 
      private SlidingDrawer slidingdrawer; 
      private ImageView imageview; 
      private int[] icons={R.drawable.main1,R.drawable.main2, 
                            R.drawable.main3,R.drawable.main4, 
                            R.drawable.main5,R.drawable.main6, 
                            R.drawable.main7,R.drawable.main8,R.drawable.main9}; 
      private String[] items={"华仔","发哥","雅芝","柏芝","周星星","jindegege","易做图","老毕","涵涵"}; 
          
        /** Called when the activity is first created. */ 
        @Override 
        public void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main); 
            gridview = (GridView)findViewById(R.id.gridview);  
            slidingdrawer = (SlidingDrawer)findViewById(R.id.sd); 
            imageview=(ImageView)findViewById(R.id.imageview); 
            MyAdapter adapter=new MyAdapter(this,items,icons);//通过构造函数实例化一个MyAdapter对象,这个MyAdapter对象必须继承BaseAdapter类  
            gridview.setAdapter(adapter); 
            slidingdrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener()//打开抽屉  
            { 
              @Override 
              public void onDrawerOpened() 
              { 
                  imageview.setImageResource(R.drawable.photo);//打开抽屉事件   
              } 
            }); 
            slidingdrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() 
            { 
              @Override 
              public void onDrawerClosed() 
              { 
                  imageview.setImageResource(R.drawable.ic_launcher);//关闭抽屉事件  
              } 
            }); 
        } 
    } 
package com.jindegege.activity;

import com.jindegege.service.MyAdapter;

import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SlidingDrawer;
public class SlidingdrawerActivity extends Activity {
 
   private GridView gridview;
   private SlidingDrawer slidingdrawer;
   private ImageView imageview;
   private int[] icons={R.drawable.main1,R.drawable.main2,
                         R.drawable.main3,R.drawable.main4,
                         R.drawable.main5,R.drawable.main6,
                         R.drawable.main7,R.drawable.main8,R.drawable.main9};
   private String[] items={"华仔","发哥","雅芝","柏芝","周星星","jindegege","易做图","老毕","涵涵"};
     
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         gridview = (GridView)findViewById(R.id.gridview);
         slidingdrawer = (SlidingDrawer)findViewById(R.id.sd);
         imageview=(ImageView)findViewById(R.id.imageview);
         MyAdapter adapter=new MyAdapter(this,items,icons);//通过构造函数实例化一个MyAdapter对象,这个MyAdapter对象必须继承BaseAdapter类
         gridview.setAdapter(adapter);
         slidingdrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener()//打开抽屉
         {
           @Override
           public void onDrawerOpened()
           {
      &nbs

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