控件问题

Button自边距

部分主题下(如AppCompatActivity),Button会自带边距,并且padding、margin设为0也没用;

android:minWidth="0dp"

PopupWindow关闭

点击外部取消和点击返回键取消

final PopupWindow popWindow = new PopupWindow(
        view,
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT, 
        true  //  点击外部取消,还不行添加下面注释代码
);
//      popWindow.setTouchable(true);
//      popWindow.setOutsideTouchable(true);
//      popWindow.setBackgroundDrawable(new ColorDrawable());
//  点击返回键取消
view.setOnKeyListener(new View.OnKeyListener(){
    @Override
    public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
        if (arg1 == KeyEvent.KEYCODE_BACK){
            popWindow.dismiss();
        }
        return false;
    }
});

ImageView图片适配

        LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) ivLogo.getLayoutParams();
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.bg_about);
        linearParams.width = DisplayUtil.getScreenWidth(this);
        linearParams.height = (int) (DisplayUtil.getScreenWidth(this) / (float) drawable.getIntrinsicWidth() * drawable.getIntrinsicHeight());
        ivLogo.setLayoutParams(linearParams);

点击编辑框外部取消软键盘

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        View view = getCurrentFocus();
        if (view != null && ev.getAction() == MotionEvent.ACTION_DOWN && view instanceof EditText) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            int x = location[0], y = location[1];
            if(ev.getX() < x || ev.getX() > (x + view.getWidth()) || ev.getY() < y || ev.getY() > (y + view.getHeight())){
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }
            }
        }
        return super.dispatchTouchEvent(ev);
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,235评论 25 709
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,693评论 1 92
  • 1;块级元素 常用的块级元素: div--无意义用在大布局上 ol --有序列表 ul --无序列表 li --列...
    web前端ling阅读 3,294评论 0 0
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 11,872评论 0 17
  • 两周前去杭州的时候,坐在西湖天地里愉快的喝茶,没想到喝着喝着,蚊子就在我两只脚踝处各咬了一圈的包,更没想到的是,居...
    cnsjw阅读 5,685评论 0 1

友情链接更多精彩内容