美文网首页
控件问题

控件问题

作者: 已经是咸鱼的小涛orz | 来源:发表于2017-09-12 17:12 被阅读0次

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);
    }

相关文章

  • 控件问题

    Button自边距 部分主题下(如AppCompatActivity),Button会自带边距,并且padding...

  • 控件关联问题

    新建一个 tableViewController,若要自定义cell的样式,需要再建一个tableViewCell...

  • AWTK 控件焦点相关问题

    控件焦点相关问题 一、启用焦点停留 (tab stop) 除了 edit 控件外,其它控件如果需要焦点停留功能,可...

  • 控件总结

    一、WebView控件1.Android 解决WebView重定向问题 二,RecyclerView控件1.Rec...

  • 20170831

    碰到一个界面上控件上的子控件位置显示错误的问题。仔细查了代码,发现在添加子控件并设置其位置的地方不存在问题,那么结...

  • 自定义控件生成问题

    问题: 前端自己拖拽控件的界面,后台将界面中的控件字段传来,有些是EditText,有些是时间控件,有些是Text...

  • 控件使用总踩雷?畅写Office带你云端飞

    使用Office必然绕不开控件。但是Office控件使用过程中却问题频发。比如控件下载、安装、配置、启动Offic...

  • BadgeView控件切换账号控件显示问题

    在首页通过BadgeView控件显示气泡数字,切换账号后,气泡数字显示问题(主要在于气泡数字从有到无,从有到有),...

  • 解决Activity进入时EditText获取焦点,使页面滑动现

    问题解决方案:是用其它控件获取焦点 比如在TextView 控件上设置焦点

  • Android 脚本自动化 SDK 原理:控件的寻找

    背景 在回放的时候。我们需要把操作绑定到具体的控件上。而控件是根据 Xpath 来识别的。 问题 控件调整因为机型...

网友评论

      本文标题:控件问题

      本文链接:https://www.haomeiwen.com/subject/qhacsxtx.html