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.
3.虚线分割线@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); }
(第一步)先在drawable目录下创建一个线line的shape文件,比如此dash_line.xml文件代码:
(第二步)然后在自己的布局文件中添加一个LinearLayout作为不同view的分割线,比如:<?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 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