利用ObjectAnimator编写弹出式二级菜单
来源:互联网 发布:linux支持哪些文件系统 编辑:程序博客网 时间:2024/04/30 15:45
当二级菜单弹出时,界面的空间可能会不够或变得拥挤。
解决:
这时可以将ToolBar和界面其它View上移,
这样因为二级菜单的弹出而让界面拥挤的问题就得到了解决。
程序效果如图所示:
MainActivity.java
public class MainActivity extends AppCompatActivity { private Toolbar mToolbar; private ImageView mImageView; private FrameLayout firstbar_layout,secondbar_layout; private int animationDuration = 300; private int animator_height,secondbar_height; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mToolbar = (Toolbar) findViewById(R.id.toolbar); //Toolbar mImageView = (ImageView)findViewById(R.id.image); //占用屏幕空间的视图,这里用了图片来代替 firstbar_layout = (FrameLayout)findViewById(R.id.firstbar); //一级菜单 secondbar_layout = (FrameLayout)findViewById(R.id.secondbar); //二级菜单 animator_height = ScreenInfoUtil.dip2px(this, 50); //界面中Toolbar和图片需要上移的高度 secondbar_height = ScreenInfoUtil.dip2px(this, 100); //二级菜单的高度 firstbar_layout.setOnClickListener(new View.OnClickListener() { //一级菜单点击事件 @Override public void onClick(View view) { moveY(0, -animator_height); moveBar(secondbar_height,0); } }); secondbar_layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //二级菜单点击事件 moveY(-animator_height, 0); moveBar(0,secondbar_height); } }); } private void moveY(float startY, float endY) { //利用ObjectAnimator实现视图的Y轴移动操作 Object[] animComponent = {mToolbar,mImageView}; //对Toolbar和ImageView进行移动 for (final Object obj : animComponent) { ObjectAnimator animator = ObjectAnimator.ofFloat(obj, "translationY", startY, endY); animator.setDuration(animationDuration).setInterpolator( new AccelerateDecelerateInterpolator()); animator.start(); } } private void moveBar(float startY, float endY) { //利用ObjectAnimator实现二级菜单的弹出操作 secondbar_layout.setVisibility(View.VISIBLE); Object[] animComponent = {secondbar_layout}; for (final Object obj : animComponent) { ObjectAnimator animator = ObjectAnimator.ofFloat(obj, "translationY", startY, endY); animator.setDuration(animationDuration).setInterpolator( new AccelerateDecelerateInterpolator()); animator.start(); } }}activity_main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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:id="@+id/root_layout" tools:context="com.lla.testviewup.MainActivity"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="50dp" android:background="?attr/colorPrimary"/> <ImageView android:layout_width="match_parent" android:layout_height="280dp" android:id="@+id/image" android:layout_marginTop="120dp" android:scaleType="centerCrop" android:background="@drawable/godness"/> <FrameLayout android:layout_width="match_parent" android:layout_height="50dp" android:id="@+id/firstbar" android:layout_alignParentBottom="true" android:background="@color/colorPrimary" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="我是一级菜单,点我弹出二级菜单"/> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="100dp" android:id="@+id/secondbar" android:layout_alignParentBottom="true" android:background="@color/bottom_bar" android:visibility="invisible"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="我是二级菜单,点我返回一级菜单"/> </FrameLayout></RelativeLayout>
0 0
- 利用ObjectAnimator编写弹出式二级菜单
- 弹出式菜单的编写
- 利用XML的网页菜单/弹出式菜单/工具条
- 弹出式菜单
- 弹出式菜单
- 弹出式菜单
- 弹出式菜单
- 弹出式菜单
- 弹出式菜单
- 利用ObjectAnimator实现侧滑菜单的效果
- MFC中教你怎么编写弹出式菜单
- 利用封装的一个函数显示一个弹出式菜单
- 事件委托的二级菜单编写
- 利用json数据做父子二级菜单
- 利用Jquery实现二级下拉菜单
- 利用HTML制作一二级导航菜单
- 利用for循环,完成二级菜单
- 制作弹出式菜单
- Dubbo服务 初学配置
- Java中Object类的equals()和hashCode()方法
- c# 把excel表格当做数据库的使用感受
- SCPPO(十五):IIS配置文件节点加密
- leetcode算法——258:Add Digits(基于JAVA)
- 利用ObjectAnimator编写弹出式二级菜单
- ajax父页面main.html
- 1024: 个位数统计
- 图象处理基本算法[整理]
- 同时上传图片与文字
- 基于Token的WEB后台认证机制
- DOS初体验
- MSP430 一种低功耗设计
- 文章标题