模仿猫眼电影App一个动画效果
2017-07-08 14:30
323 查看
看真正的猫眼效果图
接下来看自己写的粗略图(不足的地方是这里是2个切换选项,假设须要3个切换的话,须要自己定义控件,兴许在更新。。。)
源代码地址
自己定义控件(21)---自己定义控件之高仿猫眼小项目(3)
先看主页面xml布局文件--so easy
activity_main.xml
MainActivity--看主布局代码--so easy
接下来看自己写的粗略图(不足的地方是这里是2个切换选项,假设须要3个切换的话,须要自己定义控件,兴许在更新。。。)
源代码地址
自己定义控件(21)---自己定义控件之高仿猫眼小项目(3)
先看主页面xml布局文件--so easy
activity_main.xml
<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" tools:context="com.example.mytogglebutton.MainActivity" > <RelativeLayout android:layout_width="150dp" android:layout_height="50dp" android:layout_centerInParent="true" android:background="#CD5555" > <TextView android:id="@+id/tv_left" android:layout_width="50dp" android:layout_height="40dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:gravity="center" android:text="购物" /> <TextView android:id="@+id/tv_up" android:layout_width="50dp" android:layout_height="40dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:background="#ffffff" android:gravity="center" android:text="购物" /> <TextView android:id="@+id/tv_right" android:layout_width="50dp" android:layout_height="40dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="15dp" android:gravity="center" android:text="美食" /> </RelativeLayout> </RelativeLayout>
MainActivity--看主布局代码--so easy
package com.example.mytogglebutton; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { private TextView tv_left; private TextView tv_right; private TextView tv_up; //表示是否要从购物切换到美食 private boolean tv_up_left_tran = false; //表示是否要从美食切换到购物 private boolean tv_up_right_tran = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); tv_right.setOnClickListener(this); tv_left.setOnClickListener(this); } private void initView() { tv_left = (TextView) findViewById(R.id.tv_left); tv_right = (TextView) findViewById(R.id.tv_right); tv_up = (TextView) findViewById(R.id.tv_up); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.tv_left: //表示要从美食切换到购物 if (!tv_up_right_tran) { TranslateAnimation animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 1.4f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setDuration(100); tv_up.setText("购物"); animation.setFillAfter(true); tv_up.startAnimation(animation); } //切换后,改动状态--能够从左边切换到右边。可是不能从右边切换到左边 tv_up_right_tran = true; tv_up_left_tran = false; Toast.makeText(this, ""+tv_up.getText(), 1).show(); break; case R.id.tv_right: //表示要从购物切换到美食 if (!tv_up_left_tran) { TranslateAnimation animation1 = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.4f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation1.setDuration(100); tv_up.setText("美食"); tv_up.startAnimation(animation1); animation1.setFillAfter(true); } //切换后,改动状态--能够从右边切换到左边,可是不能从左边切换到右边 tv_up_left_tran = true; tv_up_right_tran = false; Toast.makeText(this, ""+tv_up.getText(), 1).show(); break; default: break; } } }
相关文章推荐
- 模仿猫眼电影App一个动画效果
- 仿魅族flyme社区app的一个动画效果
- 用jQuery和css3实现的一个模仿淘宝ued博客左边的菜单切换动画效果
- Android Animation实战之一个APP的ListView的动画效果
- Flash/Flex学习笔记(45):无聊模仿同事的一个Loading效果
- Android 动画效果 --Animation 动画(讲解了所有的Android动画效果,是一个值得收藏的帖子)
- WPF中splashScreen启动程序之前出现一个过程动画的效果
- wince如何去掉APP窗口的动画显示效果
- 一个好的模仿自定义工具栏的效果
- andriod一个不错的启动菜单显示屏动画效果
- 模仿google首页图片动画效果 (css+javascript)
- [原]模仿Google首页的PNG动画效果
- 一个APP案例:多个软件商店下载效果比较图
- 一个帖子掌握android所有控件、ProgressBar 、Android 动画效果、SQLite、四大组件、Android多媒体
- iphone 一个强大的动画效果,真的很好,很强大哦
- 使用HTML5和jQuery插件Reel实现一个超酷的星际争霸2兵种动画360度预览效果
- WPF中splashScreen启动程序之前出现一个过程动画的效果
- 一个模仿图片透明渐变做的表格颜色渐变效果 js脚本特效
- Flash/Flex学习笔记(45):无聊模仿同事的一个Loading效果
- 仿的一个动画菜单效果