Android tips

1.在application xml中使用全局的theme

2.利用runOnUiThread确保某个runnable运行在ui 线程里

3.利用<selector  <item设置button背景而不是普通的图片作为背景

4.在listView getView中利用Holer来实现图片文字的缓存,以使得listView滑动高效,避免出现无限制的调用findViewById使得多次DOM解析xml带来的低效率

 static class ViewHolder {
        protected TextView title;
        protected TextView type;

    }
    
public View getView(int position, View contentView, ViewGroup arg2)
    {
        ViewHolder holder;

        if (contentView == null) {
            holder = new ViewHolder();
            contentView = inflater.inflate(R.layout.my_magic_list,null);
            holder.label = (TextView) contentView.findViewById(R.id.label);
            contentView.setTag(holder);
        } else {
            holder = (ViewHolder) contentView.getTag();
        }

        holder.label.setText(getLabel());

        return contentView;
    }
在view.setTag缓存了Holer,Holer中保存了TextView,Java中是值传递,Holder中的textView和converView中的textView是同一个对象,所以当修改了对应行holder中的textview就同时修改了对应行中的
避免了多次调用findViewById

5.android:cacheColorHint=”@android:color/transparent”防止listView滚动时候的触摸阴影

6.EditText setError可以给出错误提示

7.阻止默认的startActivty的动画 myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)

8.TextView 多行显示 android:singleLine=”false”, android:lines=”5″

9.多利用xml来绘制重叠图片



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值