最近做的一个项目,用到了抽屉。意由心生,所以想写个关于抽屉的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. 工作中常用到的Linux命令
  2. 太简单了!PHP获取文件扩展名的7中方法
  3. php中使用fsockopen实现异步请求(代码示例
  4. php实现将表单内容提交到数据库
  5. 流行的php rpc框架详解
  6. php实现字母数字混合验证码
  7. php监听redis key失效触发回调事件
  8. 使用Docker部署PHP开发环境的方法详解
  9. PHP实现大转盘抽奖算法(代码实例)
  10. go-micro+php+consul实现简单的微服务