android学习笔记之下拉动态弹出图标菜单的实现
2015-03-25 16:52
459 查看
首先在布局上放几个重叠的图标
应用属性动画,并设置插值器
主活动如下
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(){ @Override public void onClick(View v) { // TODO Auto-generated method stub switch (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 stub for(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>
相关文章推荐
- SWT 中实现最小化到托盘图标,并只能通过托盘的弹出菜单关闭程序
- css+html+js实现多级下拉和弹出菜单
- 二级联动菜单动态刷新下拉列表的一种实现方法
- css+html+js实现下拉及多级弹出菜单
- 托盘图标和弹出菜单的实现
- 17.VC(ui)-托盘图标和弹出菜单的实现(随手代码)
- MFC实现托盘图标及弹出菜单(Popup menu)
- 使用FloatingActionButton实现可拖拽动态弹出菜单
- 原生JavaScript实现动态省市县三级联动下拉框菜单实例代码
- JavaScript实现动态下拉收起菜单+css实现动画效果
- 糍粑大叔的独游之旅-u3d实现弹出菜单(上)-动态列表
- 如何实现桌面App图标可以动态显示消息数(类似手机上的QQ图标)?
- jQuery实现淡入淡出二级下拉导航菜单的方法
- 纯JSP+DWR实现三级联动下拉选择菜单
- JavaScript实现动态广告弹出框
- javascript弹出窗口实现动态文件上传
- js实现带有搜索框的可多选的动态下拉列表
- 快速集成仿QQ弹出菜单 流畅的转场实现
- VC中实现在指定控件上弹出右键菜单