当前位置:  编程技术>移动开发
本页文章导读:
    ▪ViewGroup用onLayout兑现view的自由移动        ViewGroup用onLayout实现view的自由移动 HelloViewGroup package com.fxhy.stady.myviewGroup; import com.fxhy.stady.myviewGroup.R; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.uti.........
    ▪ 切换Activity的非一般显示效果        切换Activity的特殊显示效果 private Button button1; private Button button2; private Button button3; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity); //添.........
    ▪ Parcelable在Activity其间传递对象数组       Parcelable在Activity之间传递对象数组 1.首先你的对象需要被Parcelable Person.java public class Person implements Parcelable { private String name; private String address; public Person(String name, String address) { this.name =.........

[1]ViewGroup用onLayout兑现view的自由移动
    来源: 互联网  发布时间: 2014-02-18
ViewGroup用onLayout实现view的自由移动
  • HelloViewGroup
    package com.fxhy.stady.myviewGroup;
    
    import com.fxhy.stady.myviewGroup.R;
    
    import android.content.Context;
    import android.graphics.Rect;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.ViewGroup.LayoutParams;
    import android.view.ViewManager;
    import android.widget.ImageView;
    
    
    public class HelloViewGroup extends ViewGroup {
    
    	private float mTouchStartX;
    	private float mTouchStartY;
    	private int x = 0;
    	private int y = 0;
    	private int mSelectView = -1;
    	
    	Context mContext;
    
    	public HelloViewGroup(Context context) {
    		super(context);
    		mContext = context;
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	protected void onLayout(boolean changed, int l, int t, int r, int b) {
    		if (mSelectView != -1) {
    			View v = getChildAt(mSelectView);
    			if (v != null)
    				v.layout(x, y, x + 300, y + 500);
    			return;
    		}
    		View v = getChildAt(0);
    		if (v != null)
    			v.layout(x, y, x + 300, y + 500);
    		View v1 = getChildAt(1);
    		if (v1 != null)
    			v1.layout(x + 300, y, x + 600, y + 500);
    		View v2 = getChildAt(2);
    		if (v2 != null)
    			v2.layout(x + 600, y, x + 900, y + 500);
    	}
    
    	public boolean onTouchEvent(MotionEvent event) {
    		float down_x = event.getX();
    		float down_y = event.getY();
    		switch (event.getAction()) {
    		case MotionEvent.ACTION_DOWN:
    			if (mSelectView == -1) {
    				for (int i = 0; i < getChildCount(); i++) {
    					View child = getChildAt(i);
    					if ((child.getLeft() < down_x && down_x < child.getRight())
    							&& (child.getTop() < down_y && down_y < child
    									.getBottom())) {
    						mSelectView = i;
    						break;
    					}
    				}
    			}
    			break;
    		case MotionEvent.ACTION_MOVE:
    			x = (int) event.getRawX() - 100;
    			y = (int) event.getRawY() - 100;
    
    			this.requestLayout();
    			break;
    		case MotionEvent.ACTION_UP:
    			mSelectView = -1;
    			break;
    
    		}
    
    		return true;
    	}
    
    }
  • MainActivity
    package com.fxhy.stady.myviewGroup;
    
    
    
    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
    	Context mContext;
        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            HelloViewGroup my =  new HelloViewGroup(this);
            mContext = this;
            ImageView mIcon = new ImageView( mContext);
            ImageView mIcon1 = new ImageView( mContext);
            ImageView mIcon2 = new ImageView( mContext);
            mIcon.setImageResource(R.drawable.nvshen1);
            mIcon1.setImageResource(R.drawable.nvshen2);
            mIcon2.setImageResource(R.drawable.nvshen5);
            my.addView(mIcon);
            my.addView(mIcon1);
            my.addView(mIcon2);
            setContentView(my);
            
           
            }
            
        }
    
      
        	
        	
    
     

    
[2] 切换Activity的非一般显示效果
    来源: 互联网  发布时间: 2014-02-18
切换Activity的特殊显示效果

	private Button button1;
	private Button button2;
	private Button button3;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity);
		
		//添加界面切换效果,注意只有Android的2.0(SdkVersion版本号为5)以后的版本才支持
		int version = Integer.valueOf(android.os.Build.VERSION.SDK);   
		if(version  >= 5){
			button1 = (Button)findViewById(R.id.button1);
			button1.setOnClickListener(new OnClickListener(){

				public void onClick(View v) {
					Intent intent = new Intent(ActivitySwitch.this , Main.class);
					startActivity(intent);
					//此处添加切换的特殊效果的代码
					overridePendingTransition(R.anim.zoomin,R.anim.zoomout);
				}
				
			});
			
			button2 = (Button)findViewById(R.id.button2);
			button2.setOnClickListener(new OnClickListener(){

				public void onClick(View v) {
					Intent intent = new Intent(ActivitySwitch.this , Main.class);
					startActivity(intent);
					//此处添加切换的特殊效果的代码
					overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
				}
				
			});
			
			button3 = (Button)findViewById(R.id.button3);
			button3.setOnClickListener(new OnClickListener(){

				public void onClick(View v) {
					Intent intent = new Intent(ActivitySwitch.this , Main.class);
					startActivity(intent);
					//此处添加切换的特殊效果的代码
					overridePendingTransition(android.R.anim.fade_in , android.R.anim.fade_out);
				}
				
			});
		}
	}

 zoomin.xml

<?xml version="1.0" encoding="utf-8"?>
<set
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:interpolator="@android:anim/decelerate_interpolator">
	<scale
		android:fromXScale="2.0"
		android:toXScale="1.0"
		android:fromYScale="2.0"
		android:toYScale="1.0"
		android:pivotX="50%p"
		android:pivotY="50%p"
		android:duration="@android:integer/config_mediumAnimTime" />
</set>

 zoomout.xml

<?xml version="1.0" encoding="utf-8"?>
<set
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:interpolator="@android:anim/decelerate_interpolator"
	android:zAdjustment="top">
	<scale
		android:fromXScale="1.0"
		android:toXScale=".5"
		android:fromYScale="1.0"
		android:toYScale=".5"
		android:pivotX="50%p"
		android:pivotY="50%p"
		android:duration="@android:integer/config_mediumAnimTime" />
	<alpha
		android:fromAlpha="1.0"
		android:toAlpha="0"
		android:duration="@android:integer/config_mediumAnimTime" />
</set>   
 


 

 


    
[3] Parcelable在Activity其间传递对象数组
    来源: 互联网  发布时间: 2014-02-18
Parcelable在Activity之间传递对象数组

1.首先你的对象需要被Parcelable

Person.java

public class Person implements Parcelable
{
	private String name;
	private String address;
	
	public Person(String name, String address)
	{
		this.name = name;
		this.address = address;
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public String getAddress()
	{
		return this.address;
	}
	
	/**	下面实现的是对象的序列化*/
	public int describeContents() 
	{
		return 0;
	}
	
	public void writeToParcel(Parcel dest, int flags)
	{
		dest.writeString(name);
		dest.writeString(address);
	}
	
	public static final Parcelable.Creator<Person> CREATOR = new Creator<Person>()
	{
		public Person createFromParcel(Parcel source)
		{
			Person person = new Person("","");
			person.name = source.readString();
			person.address = source.readString();
			return person;
		}
		public Person[] newArray(int size)
		{
			return new Person[size];
		}
	};

}

 

2.

传递

class BtnSeeLocationListener implements OnClickListener
    {

		public void onClick(View v)   
		{
			
			Intent intent = new Intent();
			intent.setClass(Main.this, MapViewActivity.class);
			Bundle bundle = new Bundle();

			bundle.putParcelableArrayList(SER_KEY, personList);

                        //这里不适用Bundle应该也可以,用下面的方法替代
                       //intent.putParcelableArrayListExtra(SER_KEY, personList);

                        intent.putExtras(bundle);
			startActivity(intent);
		}
    	
    }

 

3.接收

 

Intent intent = getIntent();
personList = (ArrayList<Person>)intent.getExtras().getSerializable(Main.SER_KEY);//接收对象
 

 

 

 

 

 

 

 

 


    
最新技术文章:
▪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)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


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

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

浙ICP备11055608号-3