最近做的一个项目,用到了抽屉。意由心生,所以想写个关于抽屉的DEMO。
DEMO很简单,只要是会java的人都应该看的懂。开源的好处就是大家一起成长


类似于android:id="@id/handle" 就是引用系统的id。
  android:layout_height="fill_parent"
  android:handle="@+id/handle"
  android:content="@+id/content" android:orientation="vertical"
  android:id="@+id/slidingdrawer">

  android:handle="@+id/handle"
  android:content="@+id/content" 这两个必须要这样写,就像1+1=2一样,不要问我为什么,我也不知道。反正是系统的东西



<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >

  android:layout_height="fill_parent"
  android:handle="@+id/handle"
  android:content="@+id/content" android:orientation="vertical"
  android:id="@+id/slidingdrawer">

     android:layout_height="44dip" android:src="@drawable/icon" />

     android:layout_width="fill_parent" android:layout_height="fill_parent"
   android:background="#ffffff">

      android:id="@+id/tv"
   android:textSize="18px"
   android:textColor="#000000"
   android:gravity="center_vertical|center_horizontal"
   android:layout_width="match_parent"
   android:textStyle="bold"
   android:layout_height="match_parent">

 




package com.SlidingDraw;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.SlidingDrawer;
import android.widget.TextView;

public class SlidingDrawActivity extends Activity {
    private SlidingDrawer mDrawer;
    private ImageButton imbg;
    private TextView tv;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imbg=(ImageButton)findViewById(R.id.handle);
        mDrawer=(SlidingDrawer)findViewById(R.id.slidingdrawer);
        tv=(TextView)findViewById(R.id.tv);
        mDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener()
        {
         @Override
         public void onDrawerOpened() {
        
          imbg.setImageResource(R.drawable.icon);
         }
        
        });
        
        mDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener(){

         @Override
         public void onDrawerClosed() {
        
          imbg.setImageResource(R.drawable.icon);
         }
        
        });
        
        mDrawer.setOnDrawerScrollListener(new SlidingDrawer.OnDrawerScrollListener(){

         @Override
         public void onScrollEnded() {
          tv.setText("结束拖动");
         }

         @Override
         public void onScrollStarted() {
         tv.setText("开始拖动");
         }
        
        });
    }
}

更多相关文章

  1. android 系统架构介绍
  2. Ubuntu 9.10系统Android 2.1编译笔记
  3. 基于android的远程视频监控系统
  4. Android系统架构特点及优劣分析

随机推荐

  1. 【北亚数据恢复】重装系统后磁盘分区丢失
  2. 漫画人物如何上色?赛璐璐上色步骤
  3. 使用 Docker 一键启动环境安装 ModStart
  4. Linux-Centos7学习笔记
  5. android 自定义checkbox (转)
  6. android软键盘的使用
  7. android事件处理
  8. android中的json二之json的读写
  9. androidの高仿支付宝扫描动画效果
  10. android 获取路径目录方法以及判断目录是