点击缩小的自定义布局
来源:互联网 发布:匿名网络举报网站 编辑:程序博客网 时间:2024/05/16 03:38
实现效果两个文件
ScaleAnimationHelper
package school.zn.publib.view.RelativeLayout;import android.view.View;import android.view.animation.AccelerateInterpolator;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.ScaleAnimation;public class ScaleAnimationHelper {private static int DURATION = 200;private float scale ;ScaleAnimation myAnimation_Scale;public ScaleAnimationHelper(float scale_size) {scale = scale_size;}// 放大的类,不需要设置监听器public void ScaleOutAnimation(View view) {myAnimation_Scale = new ScaleAnimation(scale, 1.0f, scale, 1f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);myAnimation_Scale.setInterpolator(new AccelerateInterpolator());AnimationSet aa = new AnimationSet(true);aa.addAnimation(myAnimation_Scale);aa.setDuration(DURATION);aa.setFillAfter(true);view.startAnimation(aa);}public void ScaleInAnimation(View view) {myAnimation_Scale = new ScaleAnimation(1.0f, scale, 1.0f, scale,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);myAnimation_Scale.setInterpolator(new AccelerateInterpolator());AnimationSet aa = new AnimationSet(true);aa.addAnimation(myAnimation_Scale);aa.setDuration(DURATION);aa.setFillAfter(true);view.startAnimation(aa);}}
package school.zn.publib.view.RelativeLayout;import android.annotation.SuppressLint;import android.content.Context;import android.content.res.TypedArray;import android.util.AttributeSet;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.widget.RelativeLayout;import school.zn.publib.R;@SuppressLint("HandlerLeak")public class HomeRelativeLayout extends RelativeLayout {private ScaleAnimationHelper scaleAnimationHelper;private float scale_size = 1.0f; private boolean isnormal=true;private OnViewClick mOnViewClick;public HomeRelativeLayout(Context context, AttributeSet attrs) {super(context, attrs);TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.HomeRelativeLayout);scale_size = ta.getFloat(R.styleable.HomeRelativeLayout_scale_size,1.0f);scaleAnimationHelper = new ScaleAnimationHelper(scale_size);}public HomeRelativeLayout(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.HomeRelativeLayout);scale_size = ta.getFloat(R.styleable.HomeRelativeLayout_scale_size,1.0f);scaleAnimationHelper = new ScaleAnimationHelper(scale_size);}public void setOnViewClick(OnViewClick onViewClick) {mOnViewClick = onViewClick;}@Overridepublic boolean onTouchEvent(MotionEvent event) {super.onTouchEvent(event);switch (event.getAction() & MotionEvent.ACTION_MASK) {case MotionEvent.ACTION_DOWN: if(isnormal) { scaleAnimationHelper.ScaleInAnimation(HomeRelativeLayout.this); isnormal=false; }break;case MotionEvent.ACTION_MOVE: if(!isnormal) { scaleAnimationHelper.ScaleOutAnimation(HomeRelativeLayout.this); isnormal=true; }break;case MotionEvent.ACTION_UP:int[] location = new int[2];HomeRelativeLayout.this.getLocationOnScreen(location);if (inRangeOfView(HomeRelativeLayout.this, event)&& mOnViewClick != null) {mOnViewClick.onClick(HomeRelativeLayout.this.getId());} if(!isnormal) { scaleAnimationHelper.ScaleOutAnimation(HomeRelativeLayout.this); isnormal=true; }break;}return true;}private boolean inRangeOfView(View view, MotionEvent ev) {float X = ev.getRawX();float Y = ev.getRawY();int[] location = new int[2];view.getLocationOnScreen(location);int view_fromx = location[0];int view_tox = location[0] + view.getWidth();int view_fromy = location[1];int view_toy = location[1] + view.getHeight();if (X < view_fromx || X > (view_tox) || Y < view_fromy|| Y > (view_toy)) {return false;}return true;}public interface OnViewClick {public void onClick(int viewID);}}
用法:
布局中使用
<school.zn.publib.view.RelativeLayout.HomeRelativeLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginLeft="1dp" android:layout_marginRight="1dp" android:layout_weight="1.0" android:background="@drawable/red_corners_big" scale:scale_size="0.95" > <TextView android:layout_marginTop="20dp" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="考 勤" style="@style/Tab_Text" /> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@mipmap/common_btn_homepage_hotel"/> </school.zn.publib.view.RelativeLayout.HomeRelativeLayout>
0 0
- 点击缩小的自定义布局
- Canvas的使用,放大缩小的自定义布局,不同的位置不同的点击事件
- 关于自定义可以点击的的布局
- 40自定义土司&&点击事件的自定义布局
- 给自定义tabBar的按钮添加点击放大缩小的动画
- IOS 自定义tabBar的按钮添加点击放大缩小的动画
- 自定义布局某个点击区域
- 关于自定义UITableViewCell布局点击Cell消失的问题
- AlertDialog 加载自定义布局点击按钮消失的方法
- 实现点击图片的放大缩小
- Android的Notification的自定义布局按钮点击+点击按钮收回系统通知栏
- 实现图片的点击放大,再点击缩小
- Android自定义布局系列之一:流式布局(含TextView的点击事件)
- 自定义布局Dialog 自定义dialog右上角带叉号的dialog 点击右上角叉号关闭dialog
- AlertDialog 自定义布局点击按钮消失方法
- 图片点击放大缩小
- anroid 点击图形缩小
- 点击imageview缩小
- Python列表切片详解([][:][::])
- 我为微商疗伤
- 提高篇第26-27课第三题
- C++ STL中哈希表 hash_map介绍
- ThreadLocal-分析-总结
- 点击缩小的自定义布局
- 通过Hook ZwCreateProcess获取进程全路径(缓存问题解决方案)
- 如何让网站所在虚拟主机支持apk格式文件下载
- 使用JAVA如何对图片进行格式检查以及安全检查处理
- SharedPreferences
- 考生经验谈:如何做好SAT阅读的时间掌控
- Android-Activity任务栈
- IOS开发 - 如何获取不变的UDID
- Spring @PathVariable注解