实用小功能收集

1.模拟View的点击事件:

/**
     * 模拟View click 事件
     **/
    public static void doSimulateClick(View view) {
        doSimulateClick(view, view.getWidth() / 2, view.getHeight() / 2);
    }

    public static void doSimulateClick(View view, float x, float y) {
        long downTime = SystemClock.uptimeMillis();
        final MotionEvent downEvent = MotionEvent.obtain(downTime, downTime,
                MotionEvent.ACTION_DOWN, x, y, 0);
        downTime += 1000;
        final MotionEvent upEvent = MotionEvent.obtain(downTime, downTime,
                MotionEvent.ACTION_UP, x, y, 0);
        view.onTouchEvent(downEvent);
        view.onTouchEvent(upEvent);
        downEvent.recycle();
        upEvent.recycle();
    }

2.reverse动画:

	public static void startAnim(View view){
		AlphaAnimation alpha = new AlphaAnimation(1, 0.3f);
		alpha.setDuration(3000);
		alpha.setRepeatCount(1);
		alpha.setRepeatMode(Animation.REVERSE);
		alpha.setAnimationListener(new NewAnimationListener());
		view.startAnimation(alpha);
	}

	static class NewAnimationListener implements AnimationListener {

		@Override
		public void onAnimationStart(Animation animation) {

		}

		@Override
		public void onAnimationEnd(Animation animation) {
			//动画执行完的操作
		}

		@Override
		public void onAnimationRepeat(Animation animation) {
		}
	}

3.解决Dialog show后,Navigation Bar也show的bug.
@Override
    public void show() {
        // Show the dialog with NavBar hidden:Set the dialog to not focusable.
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        if(Build.VERSION.SDK_INT >= 19) {
            getWindow().getDecorView().setSystemUiVisibility(5634);
        }
        super.show();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    }
3.虚线分割线
(第一步)先在drawable目录下创建一个线line的shape文件,比如此dash_line.xml文件代码:
<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android"  
    android:shape="line" >  
      
    <!--线宽为dashWith,线之间空隙dashGap,dashGap=0dp时,是实线 -->  
    <stroke  
        android:dashGap="5dp"  
        android:dashWidth="3dp"  
        android:width="1dip"  
        android:color="@android:color/black" />  
      
    <!-- 虚线高度 -->  
    <size android:height="1.5dip" />    
      
</shape>  
(第二步)然后在自己的布局文件中添加一个LinearLayout作为不同view的分割线,比如:
<LinearLayout 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:background="@android:color/white"  
    android:orientation="vertical" >  
  
    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="csdn zhangphil" />  
  
    <LinearLayout  
        android:id="@+id/dashLine"  
        android:layout_width="match_parent"  
        android:layout_height="1.5dp"  
        android:background="@drawable/dash_line"  
        android:layerType="software"  
        android:orientation="horizontal" />  
  
    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="csdn zhangphil" />  
  
</LinearLayout>  
注意:
android:layerType="software" 这个很关键,因为新的android系统默认启用硬件加速。另外虚线高度不要太小,太小会不显示,这个很奇怪。
参考自:http://blog.csdn.net/zhangphil/article/details/49046505

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值