当前位置:  编程技术>移动开发
本页文章导读:
    ▪种SldingDrawer的实现        类SldingDrawer的实现 来自海涛给的例子,谢谢海涛一直的指导!系统的slidingDrawer貌似只能从下往上,或者从右往左!这个例子是 实现 任意方向,当然你可以将布局改为相对布局将其放在任.........
    ▪ 本范例根据当前日期获取前后N天或N月的日期        本实例根据当前日期获取前后N天或N月的日期。 #!/usr/bin/python'''''Filename: "utildate.py"author:   "zhangsong"date  :   "2009-03-24"version:  "1.00"'''from time import strftime, localtimefrom datetime import timedelta, dat.........
    ▪ 第七节(Activity的生命周期2)       第七节(Activity的生命周期二) task运行过程 把不同程序的activity组装成task放入stack中。系统展示的始终是最后压入stack的activity (先进后出,后进先出),1->2->3->4 back-->3 back-->2 如.........

[1]种SldingDrawer的实现
    来源: 互联网  发布时间: 2014-02-18
类SldingDrawer的实现
来自海涛给的例子,谢谢海涛一直的指导!

系统的slidingDrawer貌似只能从下往上,或者从右往左!

这个例子是 实现 任意方向,当然你可以将布局改为相对布局将其放在任何地方

其实就是一个自定义组件,然后将其放在 你的主程序的布局中,类似slidingDrawer那样:

一个handler,一个content布局

自定义组件的class:
public class PanelView extends LinearLayout {
	private int mDuration;
	private int mPosition;
	private Boolean isAnimation;
	private int mOrientation;
	private int BOTTOM = 1;
	private int TOP = 0;
	private int LEFT = 2;
	private int RIGHT = 3;
	private Drawable mOpenedHandle;
	private Drawable mClosedHandle;
	private Button mHandle;
	private LinearLayout mContent;

	public PanelView(Context context, AttributeSet attrs) {
		super(context, attrs);

		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Panel);

		mDuration = a.getInteger(R.styleable.Panel_animationDuration, 750);
		mPosition = a.getInteger(R.styleable.Panel_position, BOTTOM);
		isAnimation = a.getBoolean(R.styleable.Panel_animationEnable, true);
		a.recycle();

		// 根据mPosition 决定LinearLayout的android:orientation属性
		mOrientation = (mPosition == TOP || mPosition == BOTTOM) ? VERTICAL
				: HORIZONTAL;
		setOrientation(mOrientation);

		initialHandlerBg();
	}

	// 设置mHandle所用背景图
	private void initialHandlerBg() {

		if (mPosition == LEFT) {
			mOpenedHandle = getResources().getDrawable(
					R.drawable.right_switcher_expanded_background);
			mClosedHandle = getResources().getDrawable(
					R.drawable.left_switcher_expanded_background);

		} else if(mPosition == TOP){
			mOpenedHandle = getResources().getDrawable(
					R.drawable.top_switcher_collapsed_background);
			mClosedHandle = getResources().getDrawable(
					R.drawable.top_switcher_expanded_background);
		} else {
			mOpenedHandle = getResources().getDrawable(
					R.drawable.left_switcher_collapsed_background);
			mClosedHandle = getResources().getDrawable(
					R.drawable.right_switcher_expanded_background);

		}
	}

	// 回调函数 界面初始化快结束时调用 用于得到 mHandle/mContent
	protected void onFinishInflate() {
		super.onFinishInflate();
		// 得到mHandle实例
		mHandle = (Button) this.getChildAt(0);

		if (mHandle == null) {
			throw new RuntimeException("Your Panel must have a View - mHandle");
		}
		mHandle.setOnClickListener(clickListener);

		mContent = (LinearLayout) this.getChildAt(1);
		if (mContent == null) {
			throw new RuntimeException("Your Panel must have a View - mContent");
		}

		// 先移除mHandle/mContent 然后根据position决定二者的添加次序
		removeView(mHandle);
		removeView(mContent);

		if (mPosition == TOP || mPosition == LEFT) {
			addView(mContent);
			addView(mHandle);
		} else {
			addView(mHandle);
			addView(mContent);
		}

		if (mClosedHandle != null) {
			mHandle.setBackgroundDrawable(mClosedHandle);
		}

		// 隐藏 mContent
		mContent.setVisibility(GONE);

	}

	private int mContentWidth=200;
	private int mContentHeight=100;
	private int paddingTop;
	private int paddingLeft;
	private Boolean isContentExpand = false;

	@Override
	// 回调函数 此时其内所有子View 宽度/高度 都已确定
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
		super.onLayout(changed, l, t, r, b);
//		mContentWidth = mContent.getWidth();
//		mContentHeight = mContent.getHeight();

		paddingTop = this.getPaddingTop();
		paddingLeft = this.getPaddingLeft();

	}

	// 定义mHandle监听器 用于开合mContent
	OnClickListener clickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if (!isContentExpand) {
				open();
			} else {
				close();
			}

			// 置反 即:开-合-开-合-开-...
			isContentExpand = !isContentExpand;

		}
	};

	// 回调函数 用于监听 Panel 的开合 效果见:setOnClickLstener(OnClickListener listener)
	public static interface OnPanelListener {
		// - open
		public void onPanelOpened(PanelView panel);

		// - close
		public void onPanelClosed(PanelView panel);
	}

	public void open() {
		if (isAnimation) {
			doAnimationOpen();
		} else {
			doOpen();
		}

	}

	public void doOpen() {
		mContent.setVisibility(VISIBLE);

	}

	public void doAnimationOpen() {
		
		post(aOpen);
		
	}

	Runnable aOpen = new Runnable() {
		public void run() {
			TranslateAnimation animation;
			int fromXDelta = 0, toXDelta = 0, fromYDelta = 0, toYDelta = 0;
			int calculatedDuration = 0;

			if (mPosition == TOP) {
				fromYDelta = -1 * mContentHeight;
				toXDelta = 0;

				calculatedDuration = mDuration
						* Math.abs(toYDelta - fromYDelta) / mContentHeight;
			} else if (mPosition == BOTTOM) {
				fromYDelta = paddingTop;
				toYDelta = fromYDelta + 1 * mContentHeight;

				calculatedDuration = mDuration
						* Math.abs(toYDelta - fromYDelta) / mContentHeight;
			} else if (mPosition == LEFT) {
				fromXDelta = -1 * mContentWidth;
				 toXDelta= 0;

				calculatedDuration = mDuration
						* Math.abs(toXDelta - fromXDelta) / mContentWidth;
			} else if (mPosition == RIGHT) {
				fromXDelta = paddingLeft;
				toXDelta = fromYDelta + 1 * mContentHeight;

				calculatedDuration = mDuration
						* Math.abs(toYDelta - fromYDelta) / mContentHeight;
			}

			animation = new TranslateAnimation(fromXDelta, toXDelta,
					fromYDelta, toYDelta);
			animation.setDuration(calculatedDuration);
			animation.setAnimationListener(new AnimationListener() {

				@Override
				public void onAnimationStart(Animation animation) {
					mContent.setVisibility(VISIBLE);
				}

				@Override
				public void onAnimationRepeat(Animation animation) {

				}

				@Override
				public void onAnimationEnd(Animation animation) {
					postProcess();
				}
			});
			startAnimation(animation);

		}
	};

	public void close() {
		if (isAnimation) {
			doAnimationClose();
		} else {
			doClose();
		}
	}

	public void doClose() {
		mContent.setVisibility(GONE);

	}

	public void doAnimationClose() {
		post(aClose);

	}

	Runnable aClose = new Runnable() {
		public void run() {
			TranslateAnimation animation;
			int fromXDelta = 0, toXDelta = 0, fromYDelta = 0, toYDelta = 0;
			int calculatedDuration = 0;

			if (mPosition == TOP) {
				toYDelta = -1 * mContentHeight;

				calculatedDuration = mDuration
						* Math.abs(toYDelta - fromYDelta) / mContentHeight;
			} else if (mPosition == BOTTOM) {
				fromYDelta = 1 * mContentHeight;
				toYDelta = paddingTop;

				calculatedDuration = mDuration
						* Math.abs(toYDelta - fromYDelta) / mContentHeight;
			} else if (mPosition == LEFT) {

				toXDelta = -1 * mContentWidth;

				calculatedDuration = mDuration
						* Math.abs(toXDelta - fromXDelta) / mContentWidth;
			} else if (mPosition == RIGHT) {

			}

			animation = new TranslateAnimation(fromXDelta, toXDelta,
					fromYDelta, toYDelta);
			animation.setDuration(calculatedDuration);
			animation.setAnimationListener(new AnimationListener() {

				@Override
				public void onAnimationStart(Animation animation) {

				}

				@Override
				public void onAnimationRepeat(Animation animation) {

				}

				@Override
				public void onAnimationEnd(Animation animation) {
					mContent.setVisibility(View.GONE);
					postProcess();
				}
			});
			startAnimation(animation);
		}
	};
	private OnPanelListener panelListener;

	// 善后工作 比如:改变mHandle背景图 通知开合监听器
	private void postProcess() {
		if (!isContentExpand) {
			mHandle.setBackgroundDrawable(mClosedHandle);
		} else {
			mHandle.setBackgroundDrawable( mOpenedHandle);
		}

		if (panelListener != null) {
			if (isContentExpand) {
				panelListener.onPanelOpened(PanelView.this);

			} else {
				panelListener.onPanelClosed(PanelView.this);

			}
		}
	}

}


图片自己去搞定咯,随便找个做个测试就可以!

主程序的布局里面 此组件的例子:
<com.SildingDrawPanel.PanelView
		android:id="@+id/leftPanel" android:layout_width="wrap_content"
		android:layout_height="wrap_content" panel:position="left"
		panel:animationDuration="500" panel:animationEnable="true"
		android:layout_gravity="left">
		<Button android:layout_width="wrap_content"
			android:layout_height="wrap_content" />
		<LinearLayout android:orientation="vertical"
			android:layout_width="wrap_content"         android:layout_height="wrap_content">
			//content
		</LinearLayout>
	</com.SildingDrawPanel.PanelView>


组件里面用到的attrs
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<declare-styleable name="Panel">
		<attr name="animationDuration" format="integer" />
		<attr name="position">
			<enum name="top" value="0" />
			<enum name="bottom" value="1" />
			<enum name="left" value="2" />
			<enum name="right" value="3" />

		</attr>
		<attr name="animationEnable" format="boolean" />
	</declare-styleable>
</resources>


好了 附上工程

1 楼 不見不潵 2012-03-29  

    
[2] 本范例根据当前日期获取前后N天或N月的日期
    来源: 互联网  发布时间: 2014-02-18
本实例根据当前日期获取前后N天或N月的日期。
#!/usr/bin/python
'''''
Filename: "utildate.py"
author:   "zhangsong"
date  :   "2009-03-24"
version:  "1.00"
'''
from time import strftime, localtime
from datetime import timedelta, date
import calendar

year = strftime("%Y",localtime())
mon  = strftime("%m",localtime())
day  = strftime("%d",localtime())
hour = strftime("%H",localtime())
min  = strftime("%M",localtime())
sec  = strftime("%S",localtime())

def today():
    '''''
    get today,date format="YYYY-MM-DD"
    '''
    return date.today()

def todaystr():
    '''''
    get date string
    date format="YYYYMMDD"
    ''''
    return year+mon+day

def datetime():
    '''''
    get datetime,format="YYYY-MM-DD HH:MM:SS"
    '''
    return strftime("%Y-%m-%d %H:%M:%S",localtime())

def datetimestr():
    '''''
    get datetime string
    date format="YYYYMMDDHHMMSS"
    '''
    return year+mon+day+hour+min+sec

def getdayofday(n=0):
    '''''
    if n>=0,date is larger than today
    if n<0,date is less than today
    date format = "YYYY-MM-DD"
    '''
    if(n<0):
        n = abs(n)
        return date.today()-timedelta(days=n)
    else:
        return date.today()+timedelta(days=n)

def getdaysofmonth(year,mon):
    '''''
    get days of month
    '''
    return calendar.monthrange(year, mon)[1]

def getfirstdayofmonth(year,mon):
    '''''
    get the first day of month
    date format = "YYYY-MM-DD"
    '''
    days="01"
    if(int(mon)<10):
        mon = "0"+str(int(mon))
    arr = (year,mon,days)
    return "-".join("%s" %i for i in arr)

def getlastdayofmonth(year,mon):
    '''''
    get the last day of month
    date format = "YYYY-MM-DD"
    '''
    days=calendar.monthrange(year, mon)[1]
    mon = addzero(mon)
    arr = (year,mon,days)
    return "-".join("%s" %i for i in arr)

def get_firstday_month(n=0):
    '''''
    get the first day of month from today
    n is how many months
    '''
    (y,m,d) = getyearandmonth(n)
    d = "01"
    arr = (y,m,d)
    return "-".join("%s" %i for i in arr)

def get_lastday_month(n=0):
    '''''
    get the last day of month from today
    n is how many months
    '''
    return "-".join("%s" %i for i in getyearandmonth(n))
 
def get_today_month(n=0):
    '''''
    get last or next month's today
    n is how many months
    date format = "YYYY-MM-DD"
    '''
    (y,m,d) = getyearandmonth(n)
    arr=(y,m,d)
    if(int(day)<int(d)):
        arr = (y,m,day)
    return "-".join("%s" %i for i in arr)

def getyearandmonth(n=0):
    '''''
    get the year,month,days from today
    befor or after n months
    '''
    thisyear = int(year)
    thismon = int(mon)
    totalmon = thismon+n
    if(n>=0):
        if(totalmon<=12):
            days = str(getdaysofmonth(thisyear,totalmon))
            totalmon = addzero(totalmon)
            return (year,totalmon,days)
        else:
            i = totalmon/12
            j = totalmon%12
            if(j==0):
                i-=1
                j=12
            thisyear += i
            days = str(getdaysofmonth(thisyear,j))
            j = addzero(j)
            return (str(thisyear),str(j),days)
    else:
        if((totalmon>0) and (totalmon<12)):
            days = str(getdaysofmonth(thisyear,totalmon))
            totalmon = addzero(totalmon)
            return (year,totalmon,days)
        else:
            i = totalmon/12
            j = totalmon%12
            if(j==0):
                i-=1
                j=12
            thisyear +=i
            days = str(getdaysofmonth(thisyear,j))
            j = addzero(j)
            return (str(thisyear),str(j),days)

def addzero(n):
    '''''
    add 0 before 0-9
    return 01-09
    '''
    nabs = abs(int(n))
    if(nabs<10):
        return "0"+str(nabs)
    else:
        return nabs

#print today()
#print addzero(10)
print get_today_month(-1)
print get_lastday_month(3)
print get_firstday_month(3)

    
[3] 第七节(Activity的生命周期2)
    来源: 互联网  发布时间: 2014-02-18
第七节(Activity的生命周期二)

task运行过程

把不同程序的activity组装成task放入stack中。系统展示的始终是最后压入stack的activity

(先进后出,后进先出),1->2->3->4 back-->3 back-->2

如果1-->2-(finish())->3 back-->1

 

小窗口模式Activity

AndroidManifest.xml中注册Activity时,设置android:theme="@android:style/Theme.Dialog",那么此Activity会以小窗口形式打开。

创建两个Activity来测试,以下是程序运行记录的日志

打开第1个Activity 

执行first:--onCreate 
执行first:--onStart 
执行first:--onResume

打开第2个Activity 

执行first:--onPause
执行second:--onCreate
执行second:--onStart
执行second:--onResume
因为未完全遮挡第1个Activity,就没有调第1个Activity的onStop方法

 


kill时机

当调用了Activity的onpause,onstop,ondestory这3个方法时。操作系统会根据资源使用率适时的杀掉这些Activity

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
jquery iis7站长之家
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3