Android View小笔记

本文分享了Android UI编程中的一些实用技巧,包括TextView、RelativeLayout布局调整、EditText编辑及光标控制、触摸事件处理等,帮助开发者提升用户体验。

九,TextView

includeFontPadding=falseincludeFontPadding的设置,并不是我们想象的0间隙,只是去掉了一定的padding空间而已。

八,RelativeLayout

 android:layout_alignWithParentIfMissing = true如果对应的兄弟元素找不到的话就以父元素做参照物

七,

EditText不可编辑
setInputType(InputType.TYPE_NULL);


   七,调试文本,调试可以看到文字


 
tools:text="123"

 

六,ediText 设置光标问题

 

普通设置 EditText 光标显示位置的方法就是

et.setSelection(text.length()); 
et.setSelection(0); 
设置0 就是第一位了。 设置text长度就最后了。

如果还不行,那就
要先设置一下获取焦点 EditText.requestFocus() 
再去设置selection 

 

  五,请求父级View不拦截touch事件


 
requestDisallowInterceptTouchEvent(true);

,获取子View的大小的一种常用方式

mLlyConter.measure(0,0);


三,关于android:foreground设置无效的问题
    

case R.styleable.View_foreground:
    if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
        setForeground(a.getDrawable(attr));
    }
    break;

 

二,对EditText进行编辑完之后点击软键盘上的回车键或者搜索触发事件

 

 

if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                if (search_et_ship_name?.text.toString().trim { it <= ' ' }.isNotEmpty()) {
                    search_et_ship_name?.clearFocus()
                    hideSoftInput()
                }
                return@setOnEditorActionListener true
            }
            false

一,对EditText设置把软键盘上的回车键改为搜索

 

 <EditText
                android:background="@null"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="center_vertical"
                android:hint="船名、港口"
                android:imeOptions="actionSearch"
                android:singleLine="true"
                android:textColor="@color/text_color_666"
                android:textColorHint="@color/text_color_hint"
                android:textSize="14sp" /

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值