# Android 开发实用小工具

来源:互联网 发布:淘宝商城运动女装 编辑:程序博客网 时间:2024/05/20 06:56

Case 1

// 格式化小数点后位数String tmp = String.format("tmp: ¥%.2f", 1f);System.out.println(tmp); ==> tmp: ¥1.00// 也可以这么用DecimalFormat df = new DecimalFormat("0.00");String tmp = df.format(1f);System.out.println(tmp); ==> 1.00

Case 2

// 数字前位补0String tmp = String.format("tmp: %04d", 2);System.out.println(tmp); ==> tmp: 0002// 也可以这么用DecimalFormat df = new DecimalFormat("0000");String tmp = df.format(2);System.out.println(tmp); ==> 0002

Case 3

// 判断字符串是否为null或空字符TextUtils.isEmpty(null) ==> trueTextUtils.isEmpty("") ==> true// 判断字符串是否是纯数字TextUtils.isDigitsOnly("1234") ==> trueTextUtils.isDigitsOnly("a123") ==> false

Case 4

View.java /**    * 可以获取View在Screen上的坐标位置 * Computes the coordinates of this view on the screen. The argument * must be an array of two integers. After the method returns, the array * contains the x and y location in that order. * * @param location an array of two integers in which to hold the coordinates */public void getLocationOnScreen(int[] location)/** * 可以获取View在其所在Window内的坐标位置 * Computes the coordinates of this view in its window. The argument * must be an array of two integers. After the method returns, the array * contains the x and y location in that order. * * @param location an array of two integers in which to hold the coordinates */public void getLocationInWindow(int[] location)

Case 5

/**  * 如果应用内有需要自己实现Activity的堆栈管理 * 不需要在每个Activity的生命周期内挨个方法添加事件了 * registerActivityLifecycleCallbacks已经帮您实现好啦。 */public class TestApplication extends Application {    public void onCreate() {          super.onCreate();          this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {            @Override            public void onActivityStopped(Activity activity) {                // activity onStop            }            @Override            public void onActivityStarted(Activity activity) {                // activity onStart        }            @Override            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {                // activity onSaveInstanceState        }            @Override            public void onActivityResumed(Activity activity) {                // activity onResume            }            @Override            public void onActivityPaused(Activity activity) {                // activity onPause            }            @Override            public void onActivityDestroyed(Activity activity) {                // activity onDestroy            }            @Override            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {                // activity onCreate        }          });        }}

Case 6

<Space/>

Case 7

<ViewStub/>

Case 8

<Merge>

Case 9

**android:animateLayoutChanges=”true”**LinearLayout中添加View的动画的办法,支持通过setLayoutTransition()自定义动画

Case 10

GradientDrawable渐变,可实现阴影效果<shape xmlns:android="http://schemas.android.com/apk/res/android"       android:shape=["rectangle", "ring", "oval", "line"]>   <corners        android:radius="5dp"        android:bottomLeftRadius="5dp"        android:topLeftRadius="5dp"        android:bottomRightRadius="5dp"        android:topRightRadius="5dp"/>    <stroke android:color="#00ffff"        android:dashGap="3dp"        android:dashWidth="10dp"        android:width="1dp"/>    <solid android:color="#ff00"/></shape>

Case 11

Android 开发你想要的工具,这里基本都全了。http://www.apkbus.com/thread-252748-1-1.html
0 0
原创粉丝点击