android学习笔记之下拉动态弹出图标菜单的实现
来源:互联网 发布:.商城 域名注册 编辑:程序博客网 时间:2024/05/21 22:09
首先在布局上放几个重叠的图标
private int res[] = {R.id.i0, R.id.i1, R.id.i2, R.id.i3, R.id.i4, R.id.i5};然后设置最上边图标的点击事件
应用属性动画,并设置插值器
animator.setInterpolator(new BounceInterpolator());布局如下
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.animatortest3.MainActivity" > <ImageView android:id="@+id/i0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <ImageView android:id="@+id/i1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <ImageView android:id="@+id/i2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <ImageView android:id="@+id/i3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <ImageView android:id="@+id/i4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <ImageView android:id="@+id/i5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> </FrameLayout>
主活动如下
<span style="font-size:14px;">public class MainActivity extends Activity {private int res[] = {R.id.i0, R.id.i1, R.id.i2, R.id.i3, R.id.i4, R.id.i5};private List<ImageView> imageList = new ArrayList<ImageView>();private boolean flag = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); for(int i=0;i<res.length;i++){ ImageView image = (ImageView) findViewById(res[i]); image.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()){case R.id.i5:if(flag){startAnim();}else{closeAnim();}break;default:}} }); imageList.add(image); } } protected void closeAnim() {// TODO Auto-generated method stub for(int i=0;i<res.length-1;i++){ObjectAnimator animator = ObjectAnimator.ofFloat(imageList.get(i), "translationY", i * 220, 0);animator.setDuration(500);animator.setInterpolator(new BounceInterpolator());animator.setStartDelay(i*200);animator.start();flag = true;}}protected void startAnim() {// TODO Auto-generated method stubfor(int i=0;i<res.length-1;i++){ObjectAnimator animator = ObjectAnimator.ofFloat(imageList.get(i), "translationY", 0f, i * 220);animator.setDuration(500);animator.setInterpolator(new BounceInterpolator());animator.setStartDelay(i*200);animator.start();flag = false;}}@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}</span>
0 0
- android学习笔记之下拉动态弹出图标菜单的实现
- 3.1Bootstrap学习组件篇之下拉菜单、图标
- 3.1Bootstrap学习组件篇之下拉菜单、图标
- Android开发技术学习之下拉刷新功能的实现
- Android学习笔记之下拉更新控件
- jQueryMobile的组件之下拉菜单(selectMenu)
- JavaScript学习笔记之下拉选择框的操作
- jQuery之下拉菜单
- HTML之下拉菜单
- Bootstrap学习总结笔记(7)-- 基本组件之下拉菜单
- android学习之下拉列表Spinner使用
- HTML笔记(八)bootstrap之下拉菜单
- 4.2Bootstrap学习js插件篇之下拉菜单
- 网页制作学习4----博客前端之下拉菜单
- Android 高级UI组件之下拉菜单(Spanner)
- Bootstrap组件之下拉菜单
- Bootstrap之下拉菜单dropdown
- HTML实例之下拉菜单
- excel中$、&、^、/、*等各种符号的使用
- 在Tomat7上使用Redis保存Session
- TP 里 left join 实例操作
- 黑马程序员--Java语言符号
- AP-应付发票余额
- android学习笔记之下拉动态弹出图标菜单的实现
- 没有知道了没有,知道知道了知道
- Python基础 01
- JAVA面试总结
- android Service 跨进程通信
- 通过JMX远程监控JBOSS7.1应用服务器
- docker搭建私人仓库
- UIView 简介(五)嵌入式动画支持
- 跟我一步一步学爬虫---宽度优先遍历篇(四)