热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android抽屉式Activity(人人网所用(有图有真相))

---------------------------main.xml

---------------------------main.xml


android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >



android:id="@+id/slidedout_cover"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY" />


------------------------blog.xml


android:id="@+id/inner_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white" >

android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="#bb000000"
android:gravity="center_vertical"
android:orientation="horizontal" >

android:id="@+id/sample_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:background="@drawable/right" />

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I hate working 公子白"
android:textColor="#ffffff"
android:textSize="19sp" />

xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="40dip" />

------------------------------.主JAVA

package slidre.co.cc;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
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;
String loveyouString[] = new String[] {
"公子白工作室", "帅哥 帅哥 帅哥 帅哥",
"帅哥", "美女", "帅哥 帅哥 帅哥",
"帅哥 帅哥 帅哥 帅哥", "帅哥 帅哥 帅哥",
"地上的娃娃笑哈哈" };

// 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(
SettingActivity.this,
android.R.layout.simple_list_item_1,
loveyouString));
mList.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(
AdapterView arg0,
View arg1,
int arg2, long arg3) {
// if (String[0]) {
//
// }
//
if (arg2 == 1) {
Intent intent = new Intent(
SettingActivity.this,
Gongzibai.class);
startActivity(intent);
finish();

}

if (arg2==3) {

Intent intent1 = new Intent(
SettingActivity.this,
Gongzibai1.class);
startActivity(intent1);
finish();

}
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);
}
}

-----------------------项目.AVTIVITY

package slidre.co.cc;

import cn.mapplayer.engine.MiidiCredit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class SliderActivity 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(
SliderActivity.this,
R.id.inner_content);
startActivity(new Intent(
SliderActivity.this,
SettingActivity.class));
overridePendingTransition(
0,
0);
}
});
}
}

------------------加上权限ACTIVITY 以及网络



推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 在一对一直播源码使用过程中,有时会出现软键盘切换闪屏问题,就是当切换表情的时候屏幕会跳动,因此要对一对一直播源码表情面板无缝切换进行优化。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • android 触屏处理流程,android触摸事件处理流程 ? FOOKWOOD「建议收藏」
    android触屏处理流程,android触摸事件处理流程?FOOKWOOD「建议收藏」最近在工作中,经常需要处理触摸事件,但是有时候会出现一些奇怪的bug,比如有时候会检测不到A ... [详细]
  • SmartRefreshLayout自定义头部刷新和底部加载
    1.添加依赖implementation‘com.scwang.smartrefresh:SmartRefreshLayout:1.0.3’implementation‘com.s ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 今天就跟大家聊聊有关怎么在Android应用中实现一个换肤功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根 ... [详细]
  • 详解Android  自定义UI模板设计_由浅入深
    学习安卓已有一些日子,前段时间整理了不少笔记,但是发现笔记不变分享与携带。今天开始整理博客,全当是与大家分享交流与自身学习理解的过程吧。结合最近在做的一个新闻类app及学习中的问题,一点一点整理一下, ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文介绍了一款名为TimeSelector的Android日期时间选择器,采用了Material Design风格,可以在Android Studio中通过gradle添加依赖来使用,也可以在Eclipse中下载源码使用。文章详细介绍了TimeSelector的构造方法和参数说明,以及如何使用回调函数来处理选取时间后的操作。同时还提供了示例代码和可选的起始时间和结束时间设置。 ... [详细]
  • Java图形化计算器设计与实现
    本文介绍了使用Java编程语言设计和实现图形化计算器的方法。通过使用swing包和awt包中的组件,作者创建了一个具有按钮监听器和自定义界面尺寸和布局的计算器。文章还分享了在图形化界面设计中的一些心得体会。 ... [详细]
author-avatar
骑马的仓鼠
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有