1. 程式人生 > 其它 >android UI設計中遇到的坑

android UI設計中遇到的坑

技術標籤:android

前言

android開發中,總有些異想天開的想法,投入實現的時候,發現android並不如我想的那麼強大,我的想法難以得到實現,獲取將來會有所改變,在我得知改變之前,我是不會再嘗試了。

1. toast彈出框不支援點選

toast 彈出框不支援點選,看了原始碼,設定了WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,使用了反射的機制取mTN,也無法奏效

TN(String packageName, @Nullable Looper looper) {
            // XXX This should be changed to use a Dialog, with a Theme.Toast
// defined that sets up the layout params appropriately. final WindowManager.LayoutParams params = mParams; params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.width = WindowManager.LayoutParams.WRAP_CONTENT; params.format = PixelFormat.
TRANSLUCENT; params.windowAnimations = com.android.internal.R.style.Animation_Toast; params.type = WindowManager.LayoutParams.TYPE_TOAST; params.setTitle("Toast"); params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; mPackageName = packageName; if (looper == null) { // Use Looper.myLooper() if looper is not specified. looper = Looper.myLooper(); if (looper == null) { throw new RuntimeException( "Can't toast on a thread that has not called Looper.prepare()"); } }

2. toast彈出框不支援時間自定義

toast 彈出框要麼是2500ms或者是3500ms,修改為其他時間無法奏效,即便是通過反射獲取mTN來修改也同樣無法奏效。因此估計android是非常不願意開發者動toast時間的。

TN(String packageName, @Nullable Looper looper) {
            // XXX This should be changed to use a Dialog, with a Theme.Toast
            // defined that sets up the layout params appropriately.
            final WindowManager.LayoutParams params = mParams;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
            params.format = PixelFormat.TRANSLUCENT;
            params.windowAnimations = com.android.internal.R.style.Animation_Toast;
            params.type = WindowManager.LayoutParams.TYPE_TOAST;
            params.setTitle("Toast");
            params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

            mPackageName = packageName;

            if (looper == null) {
                // Use Looper.myLooper() if looper is not specified.
                looper = Looper.myLooper();
                if (looper == null) {
                    throw new RuntimeException(
                            "Can't toast on a thread that has not called Looper.prepare()");
                }
            }

3. 自定義控制元件內部控制元件id衝突,導致無法點選

當有兩個自定義控制元件時,點選id衝突的控制元件時,點選事件無法觸發。
由於專案緊急,我沒有深究。