- 浏览: 519866 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
tangyunliang:
大哥你太历害了谢谢
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
u013015029:
LZ,请问下,在// 添加消息到聊天窗口 , 这里获取Ed ...
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
endual:
怎么保持会话,我搞不懂啊
Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器 -
donala_zq:
显示:[2013-11-30 11:50:36 - Andro ...
android-----------新浪微博 -
donala_zq:
哥,运行不了啊
android-----------新浪微博
先上效果图:
[img]
[/img]
[img]
[/img]
运行程序后首先显示图:
[img]
[/img]
当点击左上角按钮时如下图:
[img]
[/img]
工程结构图:
[img]
[/img]
MainActivity:
SettingActivity:
注意布局文件:
sample.xml:
main.xml:
AndroidManifest.xml:
[img]
[/img]
[img]
[/img]
运行程序后首先显示图:
[img]
[/img]
当点击左上角按钮时如下图:
[img]
[/img]
工程结构图:
[img]
[/img]
MainActivity:
package com.amaker.renren; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample); findViewById(R.id.sample_button).setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { SettingActivity.prepare(MainActivity.this, R.id.inner_content); startActivity(new Intent(MainActivity.this, SettingActivity.class)); overridePendingTransition(0, 0); } }); } }
SettingActivity:
package com.amaker.renren; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.os.Bundle; import android.util.TypedValue; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.TranslateAnimation; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.RelativeLayout.LayoutParams; public class SettingActivity extends Activity { private ImageView mCover; private ListView mList; private Animation mStartAnimation; private Animation mStopAnimation; private static final int DURATION_MS = 400; private static Bitmap sCoverBitmap = null; // 2个步骤 // 1. activity-->other activity // 2. anim // 先切换到另一个activity // 再获得之前activity屏幕的快照将它作为一个cover覆盖在下一个屏幕的上面,然后通过动画移动这个cover,让人感觉好像是前一个屏幕的移动。 public static void prepare(Activity activity, int id) { if (sCoverBitmap != null) { sCoverBitmap.recycle(); } // 用指定大小生成一张透明的32位位图,并用它构建一张canvas画布 sCoverBitmap = Bitmap.createBitmap( activity.findViewById(id).getWidth(), activity.findViewById(id) .getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(sCoverBitmap); // 将指定的view包括其子view渲染到这种画布上,在这就是上一个activity布局的一个快照,现在这个bitmap上就是上一个activity的快照 activity.findViewById(id).draw(canvas); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 绝对布局最上层覆盖了一个imageview setContentView(R.layout.main); initAnim(); mCover = (ImageView) findViewById(R.id.slidedout_cover); mCover.setImageBitmap(sCoverBitmap); mCover.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { close(); } }); mList = (ListView) findViewById(R.id.list); mList.setAdapter(new ArrayAdapter<String>(SettingActivity.this, android.R.layout.simple_list_item_1, new String[] { " First", " Second", " Third", " Fourth", " Fifth", " Sixth" })); mList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { close(); } }); open(); } public void initAnim() { // 采用了绝对布局,绝对布局是view的左上角从(0,0)开始 @SuppressWarnings("deprecation") final android.widget.AbsoluteLayout.LayoutParams lp = new android.widget.AbsoluteLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 0, 0); findViewById(R.id.slideout_placeholder).setLayoutParams(lp); // 屏幕的宽度 int displayWidth = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getWidth(); // 右边的位移量,60dp转换成px int sWidth = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 60, getResources() .getDisplayMetrics()); // 将快照向右移动的偏移量 final int shift = displayWidth - sWidth; // 向右移动的位移动画向右移动shift距离,y方向不变 mStartAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, shift, TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, 0); // 回退时的位移动画 mStopAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, -shift, TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, 0); // 持续时间 mStartAnimation.setDuration(DURATION_MS); // 动画完成时停留在结束位置 mStartAnimation.setFillAfter(true); mStartAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { // 动画结束时回调 // 将imageview固定在位移后的位置 mCover.setAnimation(null); @SuppressWarnings("deprecation") final android.widget.AbsoluteLayout.LayoutParams lp = new android.widget.AbsoluteLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, shift, 0); mCover.setLayoutParams(lp); } }); mStopAnimation.setDuration(DURATION_MS); mStopAnimation.setFillAfter(true); mStopAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { finish(); overridePendingTransition(0, 0); } }); } public void open() { mCover.startAnimation(mStartAnimation); } public void close() { mCover.startAnimation(mStopAnimation); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // 摁返回键时也要触发动画 if (keyCode == KeyEvent.KEYCODE_BACK) { close(); return true; } return super.onKeyDown(keyCode, event); } }
注意布局文件:
sample.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/inner_content" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" > <LinearLayout android:layout_width="fill_parent" android:layout_height="45dip" android:background="#bb000000" android:gravity="center_vertical" android:orientation="horizontal" > <Button android:id="@+id/sample_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dip" android:drawableTop="@drawable/icon" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="MainActivity........" android:textColor="#ffffff" android:textSize="19sp" /> </LinearLayout> </RelativeLayout>
main.xml:
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="fill_parent" android:layout_height="fill_parent" > <FrameLayout android:id="@+id/slideout_placeholder" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#777777" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000" /> </FrameLayout> <ImageView android:id="@+id/slidedout_cover" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitXY" /> </AbsoluteLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.amaker.renren" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.amaker.renren.SettingActivity" /> </application> </manifest>
发表评论
-
Android中如何模拟一次点击(touch)事件
2014-05-06 10:41 0在Android中有时需要模拟某一个View的touch事件, ... -
Android程序Crash时的异常上报
2014-04-28 18:15 0http://blog.csdn.net/singwhatiw ... -
android程序中证书签名校验的方法
2014-04-28 17:58 1915android程序中证书签名校验的方法一 2013-02 ... -
MD5理解错了,哎
2014-03-17 14:14 0MD5只对数据加密是无法解密的,也就是说,你把100加密后,就 ... -
Android 获取网络时间
2014-03-12 11:42 2018Android 获取网络时间 在网上看到的最常见的方式有: ... -
SQLite清空表并将自增列归零
2014-03-05 18:02 1484SQLite清空表并将自增列归零 作者:Zhu Yanfeng ... -
Handler小看一下
2013-11-11 16:42 0android handler调用post方法还是阻塞 su ... -
Frame Animation小看一下
2013-10-12 16:30 727Demo运行效果图: 源码: -
动画小学一下
2013-10-12 16:14 700转自: http://www.eoeandroid.com/f ... -
Android 动画之ScaleAnimation应用详解
2013-10-12 15:49 968===============eoeAndroid社区推荐:= ... -
android开发中的一个工具类
2013-06-19 16:04 0package com.wanpu.login.dialog; ... -
android TextView怎么设置个别字体颜色并换行?
2013-06-20 09:25 1644(1)、TextView 设置个别字体颜色 TextView ... -
Android开发之文件下载,状态时显示下载进度,点击自动安装
2013-05-07 15:38 1379在进行软件升级时,需要进行文件下载,在这里实现自定义的文件下载 ... -
android中的状态保存
2013-04-07 14:21 942package com.zzl.call; import ... -
android动画基础:tween动画
2013-04-06 11:21 1187工程结构图: [img] [/img] 四个动画的xml ... -
面试中遇到的几个问题
2013-06-09 11:56 953SAX与DOM之间的区别 SAX ( ... -
Android获取其他包的Context实例,然后调用它的方法,反射!!!
2013-03-25 10:32 1169Android中有Context的概念,想必大家都知道。Con ... -
Android的内存机制和常见泄漏情形
2013-03-06 16:55 762一、 Android的内存机制 Android的程序由Ja ... -
JUnit测试小小demo
2013-03-06 16:37 1099运行效果图: [img] [/img] 项目结构图 ... -
android开发中的异常小工具
2013-03-04 15:53 869package com.zzl.tools; impor ...
相关推荐
安卓Andriod源码——仿优酷客户端图片左右滑动.zip
安卓Android源码——仿优酷客户端图片左右滑动.zip
Android应用源码之仿优酷客户端图片左右滑动(自动滑动).zip
安卓Android源码——仿优酷客户端图片左右滑动(自动滑动).zip
仿优酷Android客户端图片左右滑动
安卓Android源码——精典源码之仿优酷客户端图片左右滑动(自动滑动).zip
仿优酷Android客户端图片左右滑动(自动滑动)完整版
Android项目仿优酷Android客户端图片左右滑动(自动滑动).rar
仿优酷Android客户端图片左右滑动Bener。
Android仿优酷Android客户端图片左右滑动自动滑动.zip
仿优酷Android客户端图片左右滑动(自动滑动)
仿优酷Android客户端图片左右滑动(自动滑动).zip
这一功能允许用户在浏览图片时,图片能够自动从右向左滑动,呈现出流畅且动态的展示效果。 在实现这一功能时,开发者需要深入了解优酷Android客户端的图片展示机制,并借鉴其自动滑动的核心算法和技术。通过编写...